Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

macos - How to create a single shared framework between iOS and OS X

I am attempting to create a framework to hold the common entity classes for an app that runs on iOS and OS X. Currently I am just including the files in each target but that requires changing the data model so it get the class from the current target (since in Swift you have to specify the module that has the class in the model file). This of course means I forget at times and things don't work.

The obvious solution is to create a shared framework that holds the entity classes so that the data model always points to the same place.

The problem is there doesn't seem to be any way to create a framework that builds on both platforms.

Has anyone found a way to create a single framework, or library, that works on both platforms?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you wish to create a single dynamic framework binary, here are the steps you can follow (as outlined in http://colemancda.github.io/2015/02/11/universal-ios-osx-framework):

1. Change the project's valid architectures and supported platforms.

This should change your framework's and test unit's valid architectures and supported platforms as well. If not, then manually change them to inherit from the project's build settings.

Step One

  • Base SDK: I recommend OS X, but it will work with iOS too. Note that with with iOS as the base SDK, "My Mac" target is separated into 3 different targets.

  • Supported Platforms: macosx iphoneos iphonesimulator

  • Valid Architectures: arm64 armv7 armv7s i386 x86_64

2. Change the search paths for the Unit Test bundle

Step Two

  • Runpath Search Paths: $(inherited) @executable_path/Frameworks @loader_path/Frameworks @executable_path/../Frameworks @loader_path/../Frameworks

  • Framework Search Paths: $(SDKROOT) $(inherited)

Its a better solution than having two separate targets.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...