How to add iOS framework in iOS project effectively

痴心易碎 提交于 2019-12-11 05:56:19

问题


Recently started work on an iOS project, written in swift and objective-c. As of now, we have a monolithic repo. Now we are focusing on creating few frameworks so that we can reuse same framework across multiple apps. I would like to know your opinion on below points.

  1. If i add framework.xcodeproj in my client app project, i am able to access the framework public entities after writing the import statement. My concern is every time i build by client app project, this framework.xcodeproj is also compiling though it's code is not changed since last build nor it is dependent on any other framework.

  2. If i add framework by adding it as framework.framework and make it's entry into embed framework, i can access the public entities of the framework. What's alarming in this case is "whenever i change the code of framework do i need to update the framework in the client app project".

Is there any way to include framework in client app project where i can access the public entities and it does not get build every time i build client app project ?

It's absolutely fine if framework get's build when it's code is updated.

I have used Visual studio in past which let me build my client project without building dependent projects if there is not code change in dependent projects.


回答1:


If the framework is build every time you build your app, depends on the type of the framework:

There are Cocoa Touch Static Libraries and Cocoa Touch Frameworks.

Cocoa Touch Frameworks

They are always open-source and will be built just like your app. (So Xcode will sometimes compile it, when you run your app and always after you cleaned the project.) Frameworks only support iOS 8 and newer, but you can use Swift and Objective-C in the framework.

Cocoa Touch Static Libraries

As the name says, they are static. So they are already compiled, when you import them to your project. You can share them with others without showing them your code. Note that Static Libraries currently don't support Swift. You will have to use Objective-C within the library. The app itself can still be written in Swift.

Conclusion

If you don't mind using Objective-C, Static Libraries seem to fit your requirement, that the framework should only be built once.

But since I love Swift, I would personally recommend you to use frameworks (if you don't mind that others that use the framework can see your code). My experience showed, that it's not a big problem, that the framework is built sometimes.


AddThis wrote a good blog post about deciding whether to use Static Libraries or Frameworks.

Cocoa Touch Static Library vs. Cocoa Touch Framework



来源:https://stackoverflow.com/questions/39439595/how-to-add-ios-framework-in-ios-project-effectively

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