将纯Swift自定义框架导入到其他Swift项目中 [英] Importing pure Swift custom framework into other Swift project
问题描述
我们有一个自定义的Swift Cocoa Touch框架
, MyLog
,它有一个名为<$的简单函数C $ C> 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
in
lib。
NB: Similar things I do in Android with adding
custom_library.jar
in lib.
推荐答案
最后我得到了以下步骤的解决方案,
Finally I got the solution with below steps,
- 标记您的自定义
MyLog
项目框架
创建时 - 实施
func printLog
并构建项目(成功构建将创建/Product/MyLog.framework
文件) - 复制
/Product/Mylog.framework
使用Finder将文件导入HelloWorld
项目目录 - 关注,
HelloWorld项目 - >目标 - >构建阶段 - >链接二进制文件库 - > + - >添加其他
(从HelloWorld /
目录中选择MyLog.framework
) - 关注,
HelloWorld项目 - >目标 - >构建阶段 - >嵌入框架 - > + - >其他
(从HelloWorld /
目录中选择MyLog.framework
) - 构建
HelloWorld
并享受!
- 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!
更新1
Update 1
- 如果找不到路径,
HelloWorld Project - >目标 - >构建阶段 - >嵌入框架
请检查,HelloWorld项目 - >目标 - >一般 - >嵌入式二进制文件
在xcode的更高版本中,它将执行第5步所做的相同操作。
- 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.
这篇关于将纯Swift自定义框架导入到其他Swift项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!