Realm Swift OS X Cocoapods 示例应用程序崩溃

Realm Swift OS X Cocoapods sample app crashes

我的步骤是:

1) 在 Xcode 中,我创建了一个新的命令行 OS X Swift 应用程序并添加了他们的示例 "class Dog" 代码,加上 "import RealmSwift"在顶部。

2) 我添加了一个包含两行的 Podfile,"use_frameworks!" 和 "pod 'RealmSwift'",然后是 运行 pod install。

3) 我打开工作区,编译,运行。我收到此警告:

Not running swift-stdlib-tool: EMBEDDED_CONTENT_CONTAINS_SWIFT is enabled, but the product type 'Command-line Tool' is not a wrapper type.

这次崩溃:

dyld: Library not loaded: @rpath/libswiftAppKit.dylib Referenced from: /Users/ys1382/Library/Developer/Xcode/DerivedData/testRealmApp-gxysfwfiirxwddbklmbolznecnld/Build/Products/Debug/RealmSwift.framework/Versions/A/RealmSwift Reason: image not found

到目前为止谷歌搜索表明警告和崩溃是相关的。有什么建议吗?

我正在使用 OS X El Capitan,Xcode 7.2.1,Cocoapods 0.39.0

TiM 的评论让我发现,在撰写本文时,几乎不可能将框架添加到 Swift 命令行应用程序。 This blog post 描述了一种方法。从第 1 步开始,它表示:

  1. Create an Objective-C command line tool and change the Search Paths. Not Swift. You can create a Swift framework for the code you’d put in your command line tool, but the tool itself must not compile any Swift code. Doing so will confuse the linker and make it see duplicate declarations of the Swift library (one in the shipped .dylib, another embedded in the command line tool).

This presentation 展示了一种不同的方法,首先创建一个 Cocoa 应用程序,然后将其强制转换为命令行应用程序,共 31 个步骤。

就在那时,我想,"mmmaybe my command line tool could use some nifty graphics after all" 并制作了一个 Cocoa OSX Swift Realm Cocoapod 应用程序,它起作用了。