How to structure a Xcode project with Frameworks,

2019-03-08 15:31发布

问题:

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).

回答1:

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.



回答2:

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.