Using Cocoapods in Cocoa Touch Framework? - ios

I'm developing a framework that requires use of AFNetworking. So I started by creating a new and shiny Cocoa Touch Framework and as usual I created a pod file with the following stuff in it:
source 'https://github.com/CocoaPods/Specs.git'
pod 'AFNetworking', '~> 2.5'
Obviously on a normal project this would create the workspace and everything would be super smooth... But since I picked Cocoa Touch Framework I am not able to import AFNetowrking.h into my ProjectName.h. The error I'm getting is:
Include of non-modular header inside framework module...
So I actually looked this up! It seemed that all I need to do is to go to my build settings and set Allow Non-modular Includes In Framework Modules to yes and my problem will be solved... but that didn't help either.
Another thing I tried doing was to also set the target membership of AFNetworking.h header file to public. But that didn't resolve the issue and I'm still getting the same error.
I'd appreciate if anyone can give me a step by step mini guide on how to do this?
It is worth mentioning that I'd like to be able to use the AFNetworking library in swift as well.

When importing a module using cocoapods in your source code you must import it like
#import <AFNetworking.h>
rather than
#import "AFNetworking.h"

Here's my pod file:
source 'https://github.com/CocoaPods/Specs.git'
pod 'AFNetworking', '~> 2.5'
use_frameworks!
You need to make sure you install the beta version of CocoaPod (0.36). The only issue with this is that you will be able to run it on iOS 7 but it will not pass the validation on apple application submission (keep that in mind).

Related

Custom CocoaPod Framework with Other Cocoapods

There is so many things written about it but still I am unable to figure it out.
So here what I am doing:
I have create a Cocoapod Test Framework with code borrowed from some tutorial here and there. Repo
Podfile
platform :ios, '9.0'
target 'CocoaPodTestFramework' do
use_frameworks!
pod 'Alamofire'
pod 'SwiftyJSON'
end
In the framework I needed a http call so I used Alamofire and SwitfyJSON pods in my framework workspace. After successful buidling process I get three framework files:
CocoaPodTestFramework.framework
Alamofire.framework
SwiftyJSON.framework
Now When I want to use it a app and created a few test app to test my framework.
Swift: the app is not using cocoapod(normal Xcode Project not workspace), I simply link all the 3 framework and it work.
For Objective-C App, I did the same and it worked.
Now in the another Swift app which uses Cocoapods I have added following in my Podfile
Podfile of Sample App
platform :ios, '9.0'
target 'Cocoapod Test App' do
use_frameworks!
pod 'CocoaPodTestFramework', :path => '/Users/ABCD/Documents/Projects/TEST/CocoaPodTestFramework'
end
Now here the issue comes, whenever I tried to build the app I get
no such module 'Alamofire' in the Referenced framework and in the app it says no such module 'CocoaPodTestFramework'
Having been reading various post/forums/issue since then but unable to figure it out how can it be fixed tried adding pod 'Alamofire' and pod 'SwiftyJSON' in app Podfile as well but still getting the same error.
And also tried adding 'Alamofire' and 'SwiftyJSON' in .podspec (s.frameworks) file of the framework which gives error though.
So I want to know if there is workaround for this or if it is not possible at all?
Read somewhere to use framework project as submodule of the sample app, will this solve the issue?If yes then how can anyone else use this pod if I don't want to share the code I mean without submitting the code only sharing .framework file(Basically Its should like a SDK, source of which I can't share but need to use other pod :P, Even I would like to skip github part searching a way for that as well)
Can anyone help me out of this?
OK...
Here how I have figured it out it may help someone like me...
Podfile
s.dependency "Alamofire"
s.dependency "SwiftyJSON"
The above 2 lines have solved the issue still I don't want to close this thread until I developed the actual SDK to check if this will actually work. :)
I ran through this problem before , I created a dynamic framework that uses pods to accomplish it's process as a chat module , after dragging it to a project it can't see the sub-frameworks and give the same errors you described, finally i figured out that nested frameworks are not allowed in IOS only MACOS ,seems like framework code must be pure code without sub-frameworks to work , wrote a post in Apple forums and they responded like this

Xcode can't see objects added via Cocoapods

I have a podfile defined with the following pods.
platform :ios, '8.0'
use_frameworks!
target 'LifeStream' do
pod 'SSKeychain'
pod 'LiveSDK'
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift-2.0'
end
I installed the pods and opened up my workspace. I have found that any usage of Alamofire works fine, due to the Swift 2 version of it importing the project as a framework.
When I try to use SSKeychain classes however, I receive a
Use of unresolved identifier 'SSKeychain`
Same applies with any class I try to use in the LiveSDK.
I have a bridge header in my projects root directory, and the project is configured to use it.
#ifndef Header_h
#define Header_h
#import "SSKeychain/SSKeychain.h"
#import "LiveSDK/LiveConnectClient.h"
#endif /* Header_h */
if I change the #import from
#import "SSKeychain/SSKeychain.h"
to
#import "SSKeychain.h"
Xcode fails to compile because it can't find the file. So I assume that the bridge header is working, as the way my bridge header is built now does not generate any compiler errors caused by not finding the headers.
Bridge Header
Framework Search Paths
I have also added my project root directory to the framework search path.
Linked Frameworks
Lastly I have linked all of the frameworks to the project as well.
Am I missing something with my setup? I have not been able to get Cocoapods to work on my project for nearly a week now. I even created a brand new project thinking that mine was just messed up; which didn't change a thing. I don't know what to do from here in order to resolve this.
Edit
After doing some additional research, I found a blog post showing that you have to include your Pods directory in the User Header Search
A commenter also mentioned that if you are using the newer Cocoapods Frameworks support for Swift, then it will need to include the Frameworks/** search path. I've included both Pods/** and Frameworks/** but still have the same issue.
After some further reading, it's beginning to sound like this is a limitation of Cocoapods. From what I understand, you can't use libraries and frameworks together at the same time in a project.
Once you use use_frameworks! in your Podfile, Objective-C Pods like SSKeychain also get build as frameworks.
The actual problem is that only module imports work in the bridging header when using frameworks. Also, you might want to get rid of the bridging header entirely, as it is unnecessary when using frameworks, they can be imported directly in Swift.
To clarify what you should do to make it work:
Be sure to have use_frameworks! in your Podfile
It doesn't matter if you have a Bridging header or not. Leave it untouched
In your SWIFT file just use import Podname
That's it, you're good to go. Of course it may happen that you need to clean your project or maybe delete the derived data folder. Build and you can use it.
If you're not using any swift pods,
Try removing the use_frameworks! on your Podfile.
Run pod install on terminal.
Clean & Build !
I spent almost half an hour fixing it, I tried adding those paths on Search Paths or re-adding the bridging-header but the error was the same.
Therefore, in my case, bridging header file was not the problem, its on the Podfile .
I hope it helps!

XCode keeps forgetting imported Frameworks

I have Xcode 6.3, using Swift, importing a Parse 1.7.1 Framework as usual (dragging, copying) and I set it up in a group: Frameworks.
I compile and everything works fine for a while with it, until the compiler does not recognize this sentence anymore:
import Parse
It gives me the error:
No such module 'Parse'
A workaround is to delete the Framework and copy it again, but after a while it starts getting annoying, and I would really like to know the cause.
I only code and build in the meantime (and occasionally creating new swift files), so I can't explain why this happens.
If you're targeting iOS 8 and above, you can tell Cocoapods to use frameworks, by putting
use_frameworks!
in your Podfile, like this example:
use_frameworks!
platform :ios, '8.0'
# Parse
pod 'Parse', '~> 1.7'
I could fix the same problem by doing so.
I just fixed this same issue today with my project. I imported my obj-c framework in a swift project and it worked for a while, then xcode seemed to forget it causing the same error you have.
apple docs
I fixed it by referencing the bridging header in Build Settings.
Under Build Settings, make sure the Objective-C Bridging Header build
setting under Swift Compiler - Code Generation has a path to the
header. The path should be relative to your project, similar to the
way your Info.plist path is specified in Build Settings. In most
cases, you should not need to modify this setting.
I just typed in the name of the bridging header folderName/xxxx-BridgingHeader.h in the field that states bridging header and all was well again.

Missing required module 'CocoaLumberjack' in iOS 8 app / framework

I'm having a problem with integrating a cocoa pod (CocoaLumberjack in this case) into an iOS app and my own frameworks.
The Podfile looks like this:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, "8.0"
target "CommonModule" do
use_frameworks!
# CocoaLumberjack wasn't officially released with Swift support yet
# pod 'CocoaLumberjack'
pod 'CocoaLumberjack', :git => 'git#github.com:CocoaLumberjack/CocoaLumberjack.git', :commit => '6882fb5f03696247e394e8e75551c0fa8a035328'
xcodeproj 'CommonModule/CommonModule.xcodeproj'
end
I have a hierarchy of modules (dynamic frameworks) like this:
CommonModule
ModelsModule (has a dependency CommonModule)
And finally, the main app:
MySwiftApp (dependency both ModelsModule and CommonModule)
Now, CocoaLumberjack is used in several files in CommonModule and works as expected. However, every time I do import CommonModule in any file in ModelsModule, I get the following compile error:
~/Developer/ModelsModule/ModelsModule/SomeFile.swift:2:8: error: missing required module 'CocoaLumberjack'
import CommonModule
^
Any idea how to solve this issue?
UPDATE: Some people Recommend to use Carthage. I would like to avoid that, if possible.
You'll also need to ensure that CommonModule.framework and CocoaLumberjack.framework (and any other frameworks) are listed in the Embedded Binaries section of your application target.
All the new iOS 8-style dynamic frameworks must be embedded within your app—even those that you aren't using directly, but that are dependencies of your dependencies—so you might end up seeing references to items you don't recognize.
Incidentally, there is a new Swift-based logging engine called CleanroomLogger that might make things easier if you're having trouble interacting with CocoaLumberjack from Swift.
I am assuming that CommonModule is swift and that your also using CocoaPods 0.36 as I see your calling use_frameworks!. I'm also assuming that you're using the Obj-C version of CocoaLumberjack, and trying to use it with Swift. That use_frameworks! flag tells CocoaPods to generate frameworks of the pods for linking in your Xcode project. So you need to say at the top of your class
import CocoaLumberjack
instead of using the Swift-Bridging-Header
Here is the blog post on cocoapods.org where they talk about the how to author a pod for the new use_frameworks! flag. Scroll down to the part Common Header Pitfalls
It could also be that your podspec creates a dependency to use CocoaLumberjack, and when linked to your project CocoaLumberjack and CommonModules, but Common Module is not referencing it correctly in the library. To get past that you need to refer to it as a framework when you import it into your Objective-C library
#import <CocoaLumberjack/CocoaLumberjack.h>

Live Rendering a custom component using IB_DESIGNABLE from a pod dependency

I'm having some difficulty using IB_DESIGNABLE in a pod.
I created a custom view which I marked as IB_DESIGNABLE and made a sample project that uses it. No problems so far.
The issue happens when adding that custom view as a pod dependency. Although the project builds and runs successfully, there is an error when the storyboard that uses the custom view is opened. The Live Rendering process starts and tries to show the view live inside Interface builder but it fails with the following error:
This is too bad because we lose Live Rendering which is, in my opinion, one of the best features from Xcode 6.
Cocoapods gem version: 0.34.4
Xcode version: 6.1 (6A1052d)
I've tried with other projects that use IB_DESIGNABLE and have a podspec:
https://github.com/Eddpt/EAColourfulProgressView (Class: EAColourfulProgressView)
https://github.com/hayashi311/HRButton (Class: HRButton)
https://github.com/Estimote/iOS-Indoor-SDK (Class: ESTIndoorLocationView)
Someone else had the same issue in Estimote - Indoor Location Error but the solution described means losing Live Rendering capabilities.
Has anyone been able to use a IB_DESIGNABLE component through Cocoapods?
Error: "failed to load designables from path (null)"
This has been fixed in the latest version of Cocoapods (0.36.0.beta.1).
To install this version:
[sudo] gem install cocoapods --pre
More information about Cocoapods with frameworks here
In order to fix the Error: "failed to load designables from path (null)":
platform :ios, '7.0'
use_frameworks!
target 'test' do
pod 'EAColourfulProgressView', '~> 0.1.0'
end
target 'testTests' do
end
Add use_frameworks! to you Podfile.
When specifying your custom class in the Identity Inspector, are you specifying from which module this class should be loaded? The module should be the name of the library the class comes from.
I Resolved my problem using use_frameworks! on the PodFile, in the first Line. (don't forget the !)
IBInspectable properties must be Dynamic, so it asks for a Dynamic Linkage of the Library. By using the above line, as soon as you set the class of a control, it will build the framework and link it, resolving this binding issues. When I upgraded to beta, Parse stopped working.
Hope it helps someone.

Resources