iOS Dependency manager in Cocoa Touch Framework

久未见 提交于 2019-12-13 10:50:39

问题


I have been researching a while and with no success on how I can build a cocoa touch framework, add dependency manger for 3rd party libraries and finally add the framework in an app project.

First, I would like to say that the framework I am planning to work with will be developed and tested while I write the app, it will be a git submodule of the main git project and.

Ideally, The structure of my the whole project looks like that

Finder:

Project

Is that a good way to work?

Secondly, the main issue I am facing is how to add dependency manager in my framework

I have tried "Carthage" and "Cocoapods"

With Carthage The main project crashes as It can't find the frameworks and with "Cocoapods", because it creates a workspaces, I can't import the the framework or, at least, I don't know how to do it.

Does anyone know a way for integrating dependency manager in a cocoa touch framework with no app project configuration?

Thank you.

Removed edited part due unfair downvotes


回答1:


Carthage is my favourite manager so I can speak to that more than Cocoapods.

When you are building a framework you want to link against any dependency managed by Carthage, but NOT include them in the framework. This is relatively simple to do. Just goto your framework target and add the Carthage built frameworks from <project-dir>/Carthage/Build/<platform>. The Carthage directory should end up in you frameworks search path as well.

In your main app project you need to do the same thing, ie. add the frames from the Carthage build directories and make sure that directories in the framework search path as well.

Then you need to do one extra step. You need to add a run script phases and tell it to execute carthage copy-frameworks and then add each of the Carthage built framework files to that phase. The reason for this is the way Apple builds frameworks requires some extra work before they are copied into your application's bundle.

I suspect the reason for your crash where it could not find the frame was that this phase was not added to your app target. So when the app ran it was not able to find the framework.




回答2:


Open to edit and suggestions! To be continued when Swift Package Manager is released for iOS

Also, I want to apologise if something is not quite right.

ANSWER:

After a while trying different ways and methods and with drekka answer, I have figured out how to use Carthage as a dependency manager for my cocoa touch framework.

My Framework has all the Carthage files and folders, includes the Frameworks but it doesn't have the run script.

Because my framework contains public variables that depends on the frameworks imported, when I use them in App project Xcode can find them.

So in my App target "TheApp - General - Linked frameworks and libraries" i drag an drop the carthage framework reference:

And, indeed, the location is added into "TheApp - Build settings - Search path - Framework search path"

At this point the app compiles an runs in a simulator but crashes when runs in a real device as it is shown in the question. For solving this issue I add the Carthage scrips in "TheApp - Build phases"

And job done!

I was expecting an easier integration like the one you get with gradle in android but, by now, I think this is the best approach.



来源:https://stackoverflow.com/questions/52245882/ios-dependency-manager-in-cocoa-touch-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!