如何在 iOS 和 OS X 之间创建单个共享框架 [英] How to create a single shared framework between iOS and OS X

查看:21
本文介绍了如何在 iOS 和 OS X 之间创建单个共享框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个框架来保存在 iOS 和 OS X 上运行的应用程序的通用实体类.目前我只是在每个目标中包含文件,但这需要更改数据模型,以便从当前目标(因为在 Swift 中,您必须在模型文件中指定具有该类的模块).这当然意味着我有时会忘记并且事情不起作用.

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?

推荐答案

如果您希望创建单个动态框架二进制文件,以下是您可以遵循的步骤(如 http://colemancda.github.io/2015/02/11/universal-ios-osx-framework):

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

这应该会改变您的框架和测试单元的有效架构以及支持的平台.如果没有,则手动更改它们以从项目的构建设置继承.

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.

  • Base SDK:我推荐 OS X,但它也适用于 iOS.请注意,以 iOS 作为基础 SDK,我的 Mac"目标被分成 3 个不同的目标.

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

支持的平台:macosx iphoneos iphonesimulator

有效架构:arm64 armv7 armv7s i386 x86_64

  • 运行路径搜索路径:$(inherited) @executable_path/Frameworks @loader_path/Frameworks @executable_path/../Frameworks @loader_path/../Frameworks

框架搜索路径:$(SDKROOT) $(inherited)

它比拥有两个单独的目标更好的解决方案.

Its a better solution than having two separate targets.

这篇关于如何在 iOS 和 OS X 之间创建单个共享框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆