Re: Swift Command Line Programs that Need Swift Frameworks
Re: Swift Command Line Programs that Need Swift Frameworks
- Subject: Re: Swift Command Line Programs that Need Swift Frameworks
- From: Roland King <email@hidden>
- Date: Sun, 04 Oct 2015 09:03:34 +0800
> On 4 Oct 2015, at 03:03, Thomas Wetmore <email@hidden> wrote:
>
> I’m converting my natural language processing engine from an Objective-C static library to a Swift framework, and I just reached the point today that I need to start testing the port.
>
> I naively thought what quicker way would there be to run a test than to put together a two or three line command line program to instantiate some of the important objects to see if they get built correctly. So I created a Swift command line program, but it immediately fails with the following:
>
> dyld: Library not loaded: @rpath/libswiftAppKit.dylib
> Referenced from: /Users/ttw4/Library/Developer/Xcode/DerivedData/LifeLines-aybxjpaancakhdbudfijgqpqpbhi/Build/Products/Debug/DeadEndsKit.framework/Versions/A/DeadEndsKit
> Reason: image not found
>
> A little research indicates that it may not be possible (yet?) to run Swift command line programs if they require Swift frameworks in order to run.
>
> Can anyone confirm or contradict this?
>
> Thanks,
>
> Tom Wetmore
Indeed command line tools in Swift are a problem. One of the issues is that, in full applications, the Swift libraries are currently bundled with the executable and not referenced from a system location. This is to ensure your executable keeps working as the language changes. But command-line tools don’t have a bundle structure to put all the libraries in, they are a single executable. So Xcode will happily build them to be tested in Xcode and preprend all the paths for you, but the binary doesn’t work outside the Xcode environment.
My current process to work around this is to build apps instead of command-line tools. Start with a cocoa app template, remove the storyboard and the template application main and replace it with your own main.swift which does whatever it does and runs a runloop if necessary. This then builds your code into an App bundle structure instead of just a single binary and copies in all the swift libraries required. So your command line binary ends up inside a bundle structure with the correct libraries and the correct linker paths to run, all you’ve done is use the cocoa template to get Xcode to build a bundle structured piece of code instead of a command line.
Normally takes about 5 minutes of jiggering around to get the initial ‘hello world’ build and after that it’s indistinguishable from writing a command line tool with the command line template.
Of course if you’re testing, Xcode does have a unit test framework built right in. That’s swift-aware and easy to use, have you considered just writing unit tests?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden