How to structure a Xcode project with Frameworks, Extensions and CocoaPods - xcode6

NB: Here is a more abstract and simplified sub-set of this question.
With the addition of Touch Frameworks, Extensions and the Apple Watch Xcode 6 projects and workspaces are getting more and more complex.
If you add CocoaPods into this mix things start to get almost unmanageable.
How would I structure an Xcode project/Workspace with the following targets and dependancies? (Assumptions: I am using Git for all the components, I am using CocoaPods for all third party code, I am using Xcode 6).
MyCoolApp
Several 3rd Party UI libraries via CocoaPods
MyCoolNetworking.framework, a framework (project) I created as a Git Sub-module
AFNetworking via CocoaPods
Other data processing code via CocoaPods
MyCoolAppBusinessLogic.framework, used by app and all extensions (below)
Includes some code from CocoaPods common to app and extensions
MyCoolToadyView, a TodayView Extension target
MyCoolWatch, an Apple Watch extension target
As you can see this is a complex structure including a couple of CocoaPods instances. Any advice on how to solve any or all of these issues will be helpful.
(My plan is to write up some of my own ideas and then synthesise an answer from everyone else, this will no doubt be a living document).

More of a comment than an answer, but I don't have enough reputation for it:
Have you tried using the cocoapods xcode plugin? I use it and it structures the pods on its own, so I don't even have to worry about it.

I really think that you can use Cocoapods to create your workspace in this case, because it really helps you out, and you can add the components you want to each one of your own frameworks.
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
workspace ‘Project.xcworkspace'
target 'Project.Models’ do
xcodeproj ‘Project/Models.xcodeproj’
pod 'Alamofire', '~> 2.0'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
end
target 'Project.Business' do
xcodeproj ‘ Project/Project.Business.xcodeproj’
pod 'Alamofire', '~> 2.0'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
end
For example here is one example in how I manage to handle multiple Frameworks with multiple dependencies and resolve it into one main workspace that has all the dependencies for 3rd party libraries for each one of my projects
Hope this gives you a Hint or help you to resolve something.

Related

About pods using AFNetworking, could I have two packages of same framework in my project?

I have a problem. My project was made with 'AFNetworking', '~> 3.0' . Now I have to insert a third party library that is a binary file with the extension .a, and it was made based on 'AFNetworking', '~> 2.6.3'. So I have this dilema, I cannot set my version to '~> 2.6' cause my whole project will crash. I tried to put both packages and make a pod install but I have failed miserably. I really need both packages working together, any thoughts ?
You can't use two versions of a pod in the same podfile.
This has been discussed in the cocoapods project: https://github.com/CocoaPods/CocoaPods/issues/6400
One hope you have would be to make a local version of AFNetworking, change the pod's name, adjust the sourceCode of the local copy to rename things. This is a pretty big deal, and probably more work than just losing your dependency on AFNetworking which is really just a very light wrapper over URLSession.

Bitcode signature failure in Xcode

I updated Xcode to the last version, and now when I'm trying to compile the project I'm getting an error "Invalid bitcode signature", hovewer, the bitcode for my project is disabled. How can I fix it? What should I change to sign my bitcode correctly?
My Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'MyProjectName' do
pod 'Realm'
pod 'CorePlot'
pod 'GoogleMaps'
end
I checked already, everything is fine with it.
I'm not sure if you have the same situation with me. I only have this issue when I tried to test with iPhone device. It turns out that the debug configuration with Build Active Architecture Only is set to NO. After I set to YES, I can test with my iPhone.
I experienced this error, but it happened only when building for an iOS 10.3 iPad (despite working on an iOS 10.3 iPhone and an iOS 11.0 iPad, and all the iOS 10.3 and 11.0 simulators). Through painful process of elimination (and creating a new project from scratch), I found that my Cocoapods weren't at fault, nor was my code signing settings, nor my AppExtension, nor my tests, nor my 'build for active architecture only' setting, nor any build setting related to the term 'bitcode'.
In my setup, I had a C++ Xcode project nested within my main Swift/iOS Xcode project. Because it was never intended specifically for use in iOS, the "iOS Deployment target" had never been set (it was left on 'default'). Upon setting it explicitly to 10.3, it worked without complaint.
Nested C++ app's project settings (set iOS deployment target to the lowest iOS version you support):
Nested C++ app's target settings (for reference):
If you using pod then please check the version of all libraries, some library may be not supporting in new version , you have to update pod files for that library.
In my case, I was trying to build for a device with an iOS version lower than the deployment target.
This kind of problem came up when I linked a new static library project to my workspace. In order to solve it I tried to set both the Build Active Architecture Only and the Bitcode settings of the library to NO but no luck. Then I got across the thing that the library's Deployment Target was set to 11.0 as Xcode set the latest value to all new projects. After fixing the setting to 5.0 the problem was solved.
On my case problem occured because of I was using a 3rd party static library with different files for each architecture
I fixed the problem by removing binaries of invalid architectures.
Instead I added a multi-arch FAT binary for the 3rd party static library
Hope helps
For my case, the solution was removing a c++ library.
I found that my issue was with using 'Modules'.
Just turned off modules (had to update some header files), but that resolved my issue.
Enable Modules In Settings
In my case, the widget included in the project was causing the bitcode error.
I changed my pod file from this:
target "App" do
pod 'A'
pod 'B'
end
target "App Widget" do
pod 'A'
end
to this:
target "App" do
pod 'A'
pod 'B'
target "App Widget" do
pod 'A'
end
end
To fix this issue, most answers recommend a workaround whereby you clean your Xcode workspace/project, close Xcode, delete your Derived Data folder (this is kept in the root directory of your project by default), then finally re-open your project.
However, the above steps may not work for you. This is a hint that your project structure is in error.
When the bitcode intermediary representation of your project was released with iOS 9.0, it was done so on the provision that your entire project, including dependencies, either totally agree to use bitcode or not. From my experience, it is vital to work through all of your Pods and included Libraries/Frameworks and ensure they all use the same setting; either Yes or No. By default, this selection is Yes.
If a single dependency does not match the intended bitcode setting, this error can be thrown.
When sanity checking your dependencies and overarching project, it is important to note that there is a Use Bitcode setting for both the Project and the Target settings, so be sure to check both perspectives of the Build Settings.
I was adding static library . I created fat binary of the same library including all architectures and included in my project. This resolved my issue
In my case, I am Using Cordova Project. While building it with Xcode had the same issue and Resolved by Removing and Adding the IOS platform.
cordova platform remove ios
cordova platform add ios
If you are using cocoa pods then do "pod update"
Targets -> Build Settings ->Build Active Architecture Only
Debug -> YES
Release -> NO to YES
I face the same problem only on archiving the app.
Who can tell me the reason? You can teach all developers. It's awesome.
This solution work for me. First, try to remove all pod using terminal command pod deintegrate and then reinstall pod using terminal command pod install.
This can also occur when building for the simulator if including a framework built for ARM only (and I assume vice-versa as well).

Creating framework with Cocoapods 0.36 in objective-C

Been stuck on this past 2 days
I am trying to create my own dynamic framework on iOS 8.3. I needed to use FMDB in my framework.
With Cocoapods 0.36 installed, I did a pod install on the following Podfile
use_frameworks!
target "PoddedFramework" do
pod 'FMDB'
end
This works just fine and creates the required pod frameworks and workspace.
But, I can't find a way to use the FMDB pod in my own framework or my demo project that uses the framework.
#import <FMDB/FMDB.h>
This statement results in a "Could not build module 'FMDB'" build error in my own framework.
If I include the above statement in the public header of my framework and try to use that public header in my demo project, I get an error saying "File not found" for FMDB.h
I have seen a lot of questions regarding integration with swift, but could not find anything regarding objective-C
I have been working with that framework a few weeks ago and it has been one of my headaches, but yesterday (Feb 6, 2018) after trying many things, I made the following adjustments taking another FMDB project as an example.
After installing FMDB (2.7.2) with "pod install" and opening the .xcworkspace I thought it would be fine and I could use it, but no, I found some differences mainly in the option Search Paths -> Header Search Paths as I show in the image configuration pods Search Paths and configuration FMDBtest Search Paths.
Then link in my viewController.m with #import "FMDB.h", if it does not work, try the option #import <FMDB / FMDB.h>

Build a library for Swift and Objective-C

I need to make a library with swift that support both swift and object c project (also support xcode 5), this will be a distribution library (do not share source code). There are two ways to do this: create a Cocoa Touch Framework or create a Cocoa Touch Static Library. I make some research, but still find out the solution. It seems the Cocoa Touch Framework not support to buid a distribution library, and I'm not sure the Cocoa Touch Static Library work perfect with with Swift yet or not. Any solutions for it. Thanks.
A very good example for this kind of library is Realm.
They both support swift and objective-c project integration. Check the repo on GitHub , and browse it : here
In fact, they have all the library coded in Objective-C, and the add Support for swift specifecity with extensions on objects used by the client. (For example, check the Realm/RLMSwiftSupport.m in their repo)
EDIT
To access a Swift class in Objective-C, just add #objc(MyClass) in your Swift Class and it will be available in Objective-C files.
Read the this for more informations about Objective-C and Swift working together
I faced the same issue as you to build one Pod library for both Swift and Objective-C, using pure code respectively without messing languages or include bridging headers. Actually I didn't try it by myself, but I came to several possible solutions:
1) To use a different branches of the same repo:
pod 'YourPodLib', :git => 'https://github.com/user_name/YourPodLib.git', :branch => 'objc'
pod 'YourPodLib', :git => 'https://github.com/user_name/YourPodLib.git', :branch => 'swift'
2) Experimenting with Subspecs as a way to install a subset of your library. (official cocoapods documentation: subspec )
It probably would look like:
pod 'YourPodLib/Swift'
Maybe my approach is far away from being ideal, but I would be appreciate if you correct me or suggest a better idea.

Adding Google Framework to Xcode?

I have been using the YouTube v2 APIs for a little while and now have finally gotten around to setting up v3. So I have downloaded their frameworks/libraries from here:
svn checkout http://google-api-objectivec-client.googlecode.com/svn/trunk/ google-api-objectivec-client-read-only
And looked closely at the instructions they give for adding it to your project here:
http://code.google.com/p/google-api-objectivec-client/wiki/BuildingTheLibrary
For the life of me I cannot get my app to compile with some sort of problem. Its either and ARC problem, can't find header files or all sorts of other errors.
Hoping someone can come along who has it working and simply put some 1 2 3 steps as it would make a lot peoples lives easier as I am sure the Google APIs of all varieties are pretty relevant to a lot of people and will continue to be, thanks.
I had the same problem recently. The quickest way I could find to get the new client library up and running quickly was to install with this CocoaPod project, called iOS-GTLYouTube.
CocoaPods is a really simple way to install libraries. If that's new to you, you can check out the instructions at cocoapods.org.
Install Cocoapods if you don't have it, using your system ruby:
$ sudo gem install cocoapods
Create a Podfile located within your project with the following:
platform :ios, '7.0'
pod 'iOS-GTLYouTube'
In your project directory, using the system ruby:
$ pod install