我已经在这里阅读了与 Swift 和静态库相关的大部分问题。这个问题不是重复的,因为:
\n\n我在静态库中有以下代码:
\n\npublic extension String {\n public func clever() -> String {\n return self + "_clever"\n }\n}\n\npublic class TestMe {\n let word:String\n public init(word:String) {\n self.word = word\n }\n public func log() {\n print("TestMe.word = \\(word)")\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我执行了静态库的“产品”>“存档”,并查看日志以查找输出。
\n\n我有一个单页应用程序,与模板唯一不同的代码是:
\n\nimport UIKit\nimport StaticLib\n\nclass ViewController: UIViewController {\n\n let t = TestMe(word:"banana")\n let s = "bob"\n\n override func viewDidLoad() {\n super.viewDidLoad()\n let c = s.clever()\n print("c = \\(c)")\n t.log()\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这是我将 .a 文件和 .swiftmodule 文件夹复制到应用程序的文件夹结构。
\n\n2018-10-12T08:43:50 ~/Documents/Code/JustApp\n\xe2\x80\xb9master* M\xe2\x80\xba \xc2\xbb ls -lR Libs\ntotal 0\ndrwxr-xr-x 5 jeff staff 170 Oct 12 07:43 StaticLib\n\nLibs/StaticLib:\ntotal 64\ndrwxr-xr-x 4 jeff staff 136 Oct 12 07:43 StaticLib.swiftmodule\n-rw-r--r-- 1 jeff staff 29216 Oct 12 07:25 libStaticLib.a\n\nLibs/StaticLib/StaticLib.swiftmodule:\ntotal 40\n-rw-r--r-- 1 jeff staff 360 Oct 12 07:25 arm64.swiftdoc\n-rw-r--r-- 1 jeff staff 15068 Oct 12 07:25 arm64.swiftmodule\nRun Code Online (Sandbox Code Playgroud)\n\n它构建正常并运行。这是控制台输出。
\n\nc = bob_clever\nTestMe.word = banana\nRun Code Online (Sandbox Code Playgroud)\n\n但这是它在编辑器中的样子。
\n\n\n\n以下是我更新的各种 PATH 设置。
\n\n\n\n本次更新:
\n\n有经验的人可能会告诉我,我缺少头文件和模块映射。但这个应用程序和库都是 Swift 的。我不需要头文件或模块映射。这就是 arm64.swiftmodule 文件的作用。
\n\n那个人可能会继续说:“无论如何都要使用它们,因为这可能会解决编辑器问题。” 我尝试过,但这让问题变得更糟。
\n\n我创建了这个模块映射:
\n\nmodule StaticLib {\n header "StaticLib-Swift.h"\n export *\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我用的是StaticLib-Swift.h在“产品”>“存档”步骤中使用了 Xcode 生成的 和 。
这就是我得到的。
\n\n\n\n但同样,构建仍然成功,并且应用程序运行得很好!
\n我在项目中通过设置解决了这个问题:
ONLY_ACTIVE_ARCH = NO;
未链接的静态库的构建设置中的标志。
如果它适用于“通用 iOS 设备”而不是其他目标,那么这是我首先想到的。
希望这对你有用!
| 归档时间: |
|
| 查看次数: |
1577 次 |
| 最近记录: |