kareman / SwiftShell

A Swift framework for shell scripting.
https://kareman.github.io/SwiftShell
MIT License
1.03k stars 87 forks source link

Use within a swift project #63

Closed scifiman closed 6 years ago

scifiman commented 6 years ago

How would I use this within a swift project? Before your latest update, I setup SwiftShell like a standalone project, built it, then embedded the framework in my Xcode project. After updating SwiftShell, my project is now crashing with a message that it can't find a symbol in the framework. dyld: Symbol not found: __T010SwiftShell12AsyncCommandC12onCompletionACyACcF Referenced from: /Users/user/Desktop/myApp.app/Contents/MacOS/myApp Expected in: /Users/user/Desktop/myApp.app/Contents/MacOS/../Frameworks/SwiftShell.framework/Versions/A/SwiftShell

It's possible I don't have something right with the code, but the only difference was the compiled SwiftShell. I'm running this: let var1 = runAsync(bash: myCmd).onCompletion { command in } Grab the output by assigning var1.stdout.read() to a variable. Then a do, try to call .finish() and catch any errors.

Thanks

kareman commented 6 years ago

I created a new macOS app project, imported SwiftShell and the following code ran fine:

let var1 = runAsync(bash: "echo hi").onCompletion {
     command in self.label.stringValue = command.stdout.read()
}
do {
    try var1.finish()
} catch {
    print(error)
}

Could you try a complete clean build of your project? If that doesn't work, is there a version of your project with this problem that you could share?

scifiman commented 6 years ago

I was able to fix my issue. My swiftshell framework was compiled before one of the Xcode updates came through, either 9.3 or 9.3.1 and I needed to recompile the framework after that update. I am seeing another issue where runAsync doesn't appear to actually be running asynchronously. That is, it causes the GUI to stop responding and I see the spinning pinwheel. Is that something you want me to open a separate ticket about?

kareman commented 6 years ago

Yes a new ticket would be nice. Also code examples, and could you also check if runAsync is started from the main thread?

scifiman commented 6 years ago

Sure. Thank you.