Importing pure Swift custom framework into other Swift project(将纯 Swift 自定义框架导入其他 Swift 项目)
问题描述
让我们,我有一个自定义的 Swift Cocoa Touch 框架,MyLog,它有一个名为printLog() 的简单函数.我在不同的工作区/位置有另一个名为 HelloWorld 的 Swift 项目.现在我需要将自定义框架MyLog导入到项目HelloWorld中,这样我就可以调用MyLog.printLog()了.
Let's, I have a custom Swift Cocoa Touch framework, MyLog, which has a simple function called printLog(). I have another Swift project named HelloWorld in different workspace/location. Now I need to import the custom framework MyLog into project HelloWorld, so that I can call MyLog.printLog().
Project -> Targets -> Build Phases -> Link Binary With Libraries
不在列表中显示我的自定义库.此外,我不只是想链接我的自定义库,而是想作为独立库单独导入,以便 MyLog 中运行的更改不会反映在 HelloWorld 中.
does not show my custom library in the list. Moreover I don't just want to link my custom library, rather I want to import separately as independent library so that running changes in MyLog wont reflect in HelloWorld.
注意:我在 Android 中通过添加 custom_library.jar 来做类似的事情库.
NB: Similar things I do in Android with adding
custom_library.jarin lib.
推荐答案
最后我通过以下步骤得到了解决方案,
Finally I got the solution with below steps,
- 创建时将自定义
MyLog项目标记为Framework - 实现
func printLog并构建项目(成功构建将创建一个/Product/MyLog.framework文件) - 使用 Finder 将
/Product/Mylog.framework文件复制到HelloWorld项目目录中 - 关注,
HelloWorld 项目 ->目标 ->构建阶段->将二进制文件与库链接->+ ->添加其他(从HelloWorld/目录中选择MyLog.framework) - 关注,
HelloWorld 项目 ->目标 ->构建阶段->嵌入框架 ->+ ->其他(从HelloWorld/目录中选择MyLog.framework) - 构建
HelloWorld并享受吧!
- Mark your custom
MyLogproject asFrameworkwhen creating - Implement
func printLogand build the project (successful build will create a/Product/MyLog.frameworkfile) - Copy the
/Product/Mylog.frameworkfile intoHelloWorldproject directory using Finder - Follow,
HelloWorld Project -> Targets -> Build Phases -> Link Binary With Libraries -> + -> Add Other(selectMyLog.frameworkfromHelloWorld/directory) - Follow,
HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks -> + -> Other(selectMyLog.frameworkfromHelloWorld/directory) - Build
HelloWorldand enjoy!
更新 1
- 如果找不到路径,
HelloWorld 项目 ->目标 ->构建阶段->嵌入框架请检查,HelloWorld Project ->目标 ->一般->更高版本的 xcode 中的嵌入式二进制文件,将执行与第 5 步相同的操作.
- If you don't find path,
HelloWorld Project -> Targets -> Build Phases -> Embed Frameworksplease check,HelloWorld Project -> Targets -> General -> Embedded Binariesin the later versions of xcode, which will do the same thing step-5 does.
这篇关于将纯 Swift 自定义框架导入其他 Swift 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将纯 Swift 自定义框架导入其他 Swift 项目
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- URL编码Swift iOS 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- UITextView 内容插图 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
