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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:47:59  来源:igfitidea点击:

Importing pure Swift custom framework into other Swift project

iosxcodeswiftframeworks

提问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 HelloWorldin different workspace/location. Now I need to import the custom framework MyLoginto 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 MyLogwont reflect in HelloWorld.

不在列表中显示我的自定义库。此外,我不只是想链接我的自定义库,而是想作为独立库单独导入,以便运行中的更改MyLog不会反映在HelloWorld.

NB: Similar things I do in Android with adding custom_library.jarin lib.

注意:我在 Android 中通过添加custom_library.jarlib进行了类似的操作。

采纳答案by Sazzad Hissain Khan

Finally I got the solution with below steps,

最后我得到了以下步骤的解决方案,

Steps

脚步

  1. Mark your custom MyLogproject as Frameworkwhen creating
  2. Implement func printLogand build the project (successful build will create a /Product/MyLog.frameworkfile)
  3. Copy the /Product/Mylog.frameworkfile into HelloWorldproject directory using Finder
  4. Follow, HelloWorld Project -> Targets -> Build Phases -> Link Binary With Libraries -> + -> Add Other(select MyLog.frameworkfrom HelloWorld/directory)
  5. Follow, HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks -> + -> Other(select MyLog.frameworkfrom HelloWorld/directory)
  6. Build HelloWorldand enjoy!
  1. 将您的自定义MyLog项目标记为Framework创建时
  2. 实现func printLog并构建项目(构建成功会创建一个/Product/MyLog.framework文件)
  3. 使用 Finder将/Product/Mylog.framework文件复制到HelloWorld项目目录中
  4. 关注,HelloWorld Project -> Targets -> Build Phases -> Link Binary With Libraries -> + -> Add OtherMyLog.frameworkHelloWorld/目录中选择)
  5. 关注,HelloWorld Project -> Targets -> Build Phases -> Embed Frameworks -> + -> OtherMyLog.frameworkHelloWorld/目录中选择)
  6. 建造HelloWorld和享受!

Update 1

更新 1

  1. 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.
  1. 如果你没有找到路径, 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

将框架添加到“嵌入式二进制文件”(目标 > 常规 > 嵌入式二进制文件)然后运行