Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm Swift OS X Cocoapods sample app crashes

My steps were:

1) In Xcode, I create a new command-line OS X Swift app and add their example "class Dog" code, plus "import RealmSwift" at the top.

2) I add a Podfile with two lines, "use_frameworks!" and "pod 'RealmSwift'" and then run pod install.

3) I open the workspace, compile, and run. I get this warning:

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

And this crash:

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

So far googling indicates the warning and crash are related. Any suggestions?

I'm using OS X El Capitan, Xcode 7.2.1, Cocoapods 0.39.0

like image 602
Yusuf X Avatar asked Feb 16 '16 04:02

Yusuf X


1 Answers

TiM's comment led me to find out that, as of this writing, it's almost impossible to add frameworks to Swift command-line apps. This blog post describes one way. Starting with step 1, it says:

  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 shows a different approach, starting with creating a Cocoa app, and then coercing it into a command-line app, in 31 steps.

It was at that point I thought, "mmmaybe my command line tool could use some nifty graphics after all" and made a Cocoa OSX Swift Realm Cocoapod app instead, which worked.

like image 136
Yusuf X Avatar answered Sep 28 '22 00:09

Yusuf X