Effectively use a library included with CocoaPods - afnetworking

This is my first attempt with CocoaPods. So far so good, I've been able to include a library create the first workspace with the library that I needed. This is my podfile:
platform :ios, '8.0'
use_frameworks!
target 'SDK-auth' do
pod 'AFOAuth2Manager', '~> 2.2'
end
Now I'm trying to use the AFOAuth2Manager lib inside my project and here is my question... what I've to do to include it? Currently I'm writing something like
#import AFOAuth2Manager;
but I receive this error: Could not build module AFOAuth2Manager
Is this the right way to include the module? or am I doing anything wrong?

Related

Add cocoa pod to iOS independent Framework

I would like to create a framework that is archived and distributed on its own. The problem I'm having is that I would like this library to have cocoa pod dependency libraries compiled into it. Is this possible?
It seems to work. But when I embed the framework in a sample app and invoke code of the embedded dependency I get an error: dyld: Library not loaded:... Reason: image not found
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'MySDK' do
use_frameworks!
pod 'ALBNoSQLDB', '~> 4.2'
end
Do I have to run an archive script to embed the dependent pods? Is this even possible?
Thanks.

Cocoapods: no such module 'CorePlot'

I have an Objective-C project.
Most of files are written in Objc
Several custom UIView classes are written in Swift.
Specially one of UIViewController subclass using Core-Plot is written in Objc.
It has no problem, until...
Now, I am trying to create a new UIViewController using Core-Plot written in Swift.
Trying to use import CorePlot to import external framework Core-Plot as described here. But the compiler shows the error "No such module 'CorePlot'"
Here is my Podfile:
platform :ios, '8.0'
target 'Meters' do
# use_frameworks!
# Pods for Meters
pod 'PQFCustomLoaders', '~> 1.1.0'
pod 'CorePlot'
end
I have used pod install and 'pod update'
I tried "Clean and rebuild"
Neither works for me. Please let me know if any other information needed.
You have to build pods as frameworks (uncomment use_frameworks! in the pod file) to create modules. Core Plot will work fine that way but I don't know about the other pod you're using.

Include file in Podfile

I have an app that consists of many modules which are linked using cocoapods. The linked modules are detected at runtime. Now I want to be able to add and remove modules from the buildserver. What I need to do now is remove or add dependencies to the Podfile before installing.
I think it would be very nice if I could write the depencies in a separate file per target and include those in the Podfile. That way I don't need to modify the Podfile when building. I'm looking for something like the #include preprocessor directive in C but I learned that the include and require functions in ruby work much different. My best success so far was to try loadbut it fails with Invalid 'Podfile' file: undefined method 'pod' for main:Object..
Is there any possibility to include a file?
Not sure if this is supported or not, but it does work if you create a function in your module file which is called from the main Podfile.
Podfile:
platform :ios, '9.0'
use_frameworks!
load 'ModulePods.rb'
abstract_target 'CommonPods' do
module_pods
pod 'SAMKeychain'
target 'Target' do
pod 'RealmSwift
end
end
ModulePods.rb:
def module_pods
pod 'ReachabilitySwift', '4.1.0'
end

Unable to use both Swift and Obj-C libs with Cocoapods

I have just started a new Swift project and I would like to use different libraries. In particular, I would like to use Realm.io, an Obj-C library. But, I would also like to use pure Swift libraries such as Alamofire or Dollar.
I use Cocoapods for managing my dependencies. I use the latest version (0.37.0) and the new use_frameworks! flag. pod install is successful anytime.
Unfortunately, when I try to build my project I get two errors (for my main target):
Umbrella header Realm.h not found from module.modulemap
Could not build Objective-C module Realm from any file using import Realm
Other imports work fine.
I have noticed the following: if I remove pure Swift libs and use_frameworks, everything works fine. I am aware about this current issue from Cocoapods. However, it should not be a problem for Realm asks developers to use that flag.
Here is my Podfile:
platform :ios, '8.0'
use_frameworks!
target 'rothrock' do
pod 'Realm'
pod 'Cent'
pod 'SwiftyJSON'
pod 'Alamofire'
end
target 'rothrockTests', :exclusive => true do
end
I use no bridging header. Should I?
Any idea or workaround?
Alright, here is the full walkthrough:
Install dependencies using Cocoapods and the use_frameworks! flag.
As you need to use a Objective-C dependency, create a Bridging header. You can create one easily by importing an Objective-C class to your Swift project, than remove it (the wizard should ask you if need a bridging header). Otherwise, create a new header file. Then, navigate to your target configuration and enter the name of your file in Swift Compiler - Code Generation > Objective-C Bridging header.
Still in your target configuration, add a new entry in Search Paths > User Header Search Paths: Pods as value and flag it as recursive.
Remove any import instruction from your code, relative to your Objective-C library.
Build your project. You should have a success.
You need a bridging header and import your Objective-C library headers there.
If you are using only Realm you can check out this documentation for Swift http://realm.io/docs/cocoa/ (go to CocoaPods down in the tabs)
Swift
Install CocoaPods 0.36.0 or later ([sudo] gem install cocoapods).
In your Podfile, add use_frameworks! and pod 'Realm' to your app target.
From the command line, run pod install.
Use the .xcworkspace file generated by CocoaPods to work on your project!
Download the latest release of Realm and extract the zip.
Drag the file at Swift/RLMSupport.swift into the File Navigator of your Xcode project, checking the Copy items if needed checkbox.
I just installed the Realm library in a project I have with some of the libraries you mention above like Alamofire and SwiftyJSON and others and it works fine when you build the project and even put the import Realm, no compilation errors at all.
I'm using Cocoapods 0.36.0, the stable version and this is my PodFile :
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
platform :ios, '8.0'
link_with 'ApiWorkflow', 'ApiWorkflowTests'
pod 'SwiftyJSON', '~> 2.2'
pod 'Alamofire', '~> 1.2'
pod 'Typhoon', '~> 3.0'
pod 'SwiftCSV', '~> 0.1'
pod 'Realm'
I hope this help you

Could not build Objective-C module 'zipzap'

I would like to use zipzap library in my swift ios project.
I use cocoapods to integrate it. When I run pod install everything works fine, but when I do import zipzap, it says Could not build Objective-C module 'zipzap'.
I've done everything that people recommend here and in similar questions. But no luck.
Is it possible that this library simply not compatible with swift-based projects?
This is my Podfile:
# Uncomment this line to define a global platform for your project
# platform :ios, '6.0'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'MyProject-iOS' do
pod 'Reachability', '~> 3.2'
pod 'SwiftyJSON', '~> 2.1'
pod 'zipzap', '~> 8.0'
end
target 'MyProject-iOSTests' do
end
I faced the same issue. Looks like the podspec for zipzap is missing. Due to which pod ends up making all header files public. And that is what causes the issue.
I wrote my own podspec file which only makes five headers public, rest are private. This decision was based on the podspec.json found in the zipzap repo.
I included zipzap in my project as follows:
pod 'zipzap', :podspec => 'https://raw.githubusercontent.com/tahasamad/zipzap/master/zipzap.podspec'
I'm the author of ZipZap. Version 8.0.4 now properly supports iOS and OS X frameworks, both with and without CocoaPods. After updating with CocoaPods, you should just be able to import ZipZap in Swift and "it just works".
In order to get correct exception handling, you'll have to use CocoaPods 0.36 or later, otherwise you may get some build warnings.

Resources