xcode 将纯 Swift 自定义框架导入其他 Swift 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37108539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Importing pure Swift custom framework into other Swift project
提问by Sazzad Hissain Khan
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()
.
让我们,我有一个自定义的 Swift Cocoa Touch framework
, MyLog
,它有一个简单的函数,叫做printLog()
. 我HelloWorld
在不同的工作区/位置有另一个 Swift 项目。现在我需要将自定义框架MyLog
导入到项目中HelloWorld
,以便我可以调用MyLog.printLog()
.
Project -> Targets -> Build Phases -> Link Binary With Libraries
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
.
不在列表中显示我的自定义库。此外,我不只是想链接我的自定义库,而是想作为独立库单独导入,以便运行中的更改MyLog
不会反映在HelloWorld
.
NB: Similar things I do in Android with adding
custom_library.jar
in lib.
注意:我在 Android 中通过添加
custom_library.jar
lib进行了类似的操作。
采纳答案by Sazzad Hissain Khan
Finally I got the solution with below steps,
最后我得到了以下步骤的解决方案,
Steps
脚步
- Mark your custom
MyLog
project asFramework
when creating - Implement
func printLog
and build the project (successful build will create a/Product/MyLog.framework
file) - Copy the
/Product/Mylog.framework
file intoHelloWorld
project directory using Finder - Follow,
HelloWorld Project -> Targets -> Build Phases -> Link Binary With Libraries -> + -> Add Other
(selectMyLog.framework
fromHelloWorld/
directory) - Follow,
HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks -> + -> Other
(selectMyLog.framework
fromHelloWorld/
directory) - Build
HelloWorld
and enjoy!
- 将您的自定义
MyLog
项目标记为Framework
创建时 - 实现
func printLog
并构建项目(构建成功会创建一个/Product/MyLog.framework
文件) - 使用 Finder将
/Product/Mylog.framework
文件复制到HelloWorld
项目目录中 - 关注,
HelloWorld Project -> Targets -> Build Phases -> Link Binary With Libraries -> + -> Add Other
(MyLog.framework
从HelloWorld/
目录中选择) - 关注,
HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks -> + -> Other
(MyLog.framework
从HelloWorld/
目录中选择) - 建造
HelloWorld
和享受!
Update 1
更新 1
- If you don't find path,
HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks
please check,HelloWorld Project -> Targets -> General -> Embedded Binaries
in the later versions of xcode, which will do the same thing step-5 does.
- 如果你没有找到路径,
HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks
请检查,HelloWorld Project -> Targets -> General -> Embedded Binaries
在更高版本的 xcode 中,它会做同样的事情 step-5 做的事情。
回答by priya
add the frameworks to "Embedded Binaries" (Target > General > Embedded Binaries) then run
将框架添加到“嵌入式二进制文件”(目标 > 常规 > 嵌入式二进制文件)然后运行