I am in need of a code for a button in Xcode that will allow me to run a .jar file? I knoe how to do this in apple script and have compiled my own app outside of xcode but now how to do it in xcode appears to be a massive case of trial and error. Could you please assist or direct me in anyway?
I went through the tutorial and keep getting an error in the viewDidLoad section. I’ve even gone as far as copying your ViewController code and pasting it in and still get the error.
The error is: Thread 1: EXC_BAD_INSTRUCTION (code-EXC_I386_INVOP, subside = 0x0)
Could this be caused by something when I was stacking, pinning, and auto layout adjust?
I’m new to the Swift / Mac programming and am at a loss.
The problem with EXC_BAD_INSTRUCTION is that they’re quite difficult to diagnose. My guess in your situation is an implicitly unwrapped optional (i.e, !) which isn’t unwrapping correctly. The most likely place you’ll come across that in this tutorial is with an unconnected @IBOutlet.
Notice that all the @IBOutlet properties are all defined as implicitly unwrapped optionals - that tells the complier that they’ll definitely exist at runtime, so don’t worry about it. If (as I’m guessing in your case) they don’t exist at runtime then you’ll see a crash like the one you’re seeing.
This is because they’re not connected to the storyboard elements correctly. You need to open the storyboard and view controller side-by-side and check that the view elements are correctly connected to the outlets in code.
Hope that’s helpful. It’s a common problem, and I think that error message should be able to give you more info. Something along the lines of “unexpectedly found nil when unwrapping optional”.
Thanks Sam! Your explanation was much clearer than any of the others I had come across. Seems I was misinterpreting one of the instructions in the tutorial. That lead to the unwrapping / nill situation. So I asked the magic 8 if Sam was a good guy and the result was “Totally”.
Great tutorial for beginners. It is clearly and nicely written.
I just want to make a comment on something, I just started with OS X applications development, I am using El Capitan with XCode 8.2.1. XCode is complaining about the “hidden” property of NSView (NSTextField), it has “isHidden” (Apple Developer Documentation), once corrected the error disappear. Worth updating the tutorial?.
As @duff for some reason my tests also reveal, when asked about Sam’s goodness, “Totally” as result.
Thank you very much again for such a great tutorial.
Thanks for pointing out the change in naming. That is part of the so-called “grand-renaming” that accompanied Swift 3. Lots of boolean properties are now prefixed with is.
Regarding updating the tutorial, the macOS team has it in its sights to bring this fully up-to-date with macOS Sierra and Swift 3. Hopefully it’ll be done some time in the near future.
Glad you enjoyed the tutorial—thank you for your kind words.
There is no “update frames” available in the “resolve auto layout issues” button from the bottom of Xcode. From the “editor” menu there is, but it’s always grayed out.
I cannot get the “Piece Of Advice” text to line up inside the magic 8 ball image (it looks like it’s all lined up in the IB).
Make sure that you’ve provided the required constraints for both the label and the image. It sounds like there are missing constraints—that’ll result in the behaviour you’re seeing where it looks right in IB but not at runtime.
The “Update Frames” menu won’t appear if you don’t have the right thing selected, and if there aren’t any updates available. Ensure you’ve selected the right label, and that the constraints are present.
Using Swift 3, Xcode 8.2 and have a problem with “Add the following line to the handleWelcome(_ method body:” welcomeLabel.stringValue = "Hello \(nameTextField.stringValue)!"
The “Update Frames” has been removed. You now have to click the first icon (currently grayed out) on the left. It looks like a “Refresh web page” icon. You need to know that if your frames are set up correctly then the icon will be greyed out so you can not click it. Just drag some views around and it will change to normal and then click it. Hope this helps.
@samdavies My son and I are very impressed with your tutorial; he was challenged to build an app for his school’s STEM Fair, and we really enjoyed working together on this. Everything went well until we reached the Initial Setup near the end (the ball and the words were in place when it ran, and we were able to click back and forth between the 8 and the advice). When we got the the Initial Setup step, we followed your directions and, later, even downloaded your completed example to compare our coding (everything looks alike to my untrained eye, although we did leave out the input name part). However, for whatever reason, when we run the app now we are unable to click to the advice side. It is driving me crazy because I know I’m doing something wrong. From the main storyboard, the click gesture recognizer is enabled, and nothing changed aside from coding between when it was clickable and now. Any thoughts?