kodeco.com Forums

macOS Development for Beginners: Part 1

In this macOS development tutorial for beginners, learn how to create your first "Hello, World" app with Swift and take a tour of Xcode.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/731-macos-development-for-beginners-part-1

My Macbook Pro can’t download Sierra. Do I really need Sierra? I feel it’s unfair.

I wrote and tested the tutorial on macOS Sierra, but it should work on earlier versions of OS X, provided you can install Xcode version 8.

1 Like

Sure there are some changes from Yosemite or some other version to Sierra, but major apps still support earlier versions and there is no problem getting started on an earlier OS. I have had a quick look at the tutorial and I think the main requirement is the ability run Xcode, so you can get started. You might find a minor difference but there is no reason to avoid it completely.

That said think about updating that MacBook some time… it’s good to be current especially in the Apple world.

(Sarah’s answer beat me by a minute :grinning: - there’s two people encouraging you.)

1 Like

Thank you for the great tutorial… I’m glad there is some MacOS tutorials…

Thanks for the macOS tutorials! I’ve wanted to program for the Mac for a long time. Hoping to be able to leverage my iOS knowledge.

I’ve followed the tutorial but I can’t get the helloLabel to display the greeting. It will always only show ‘Hello’, even though the greeting variable is getting set properly to either Hello World! in the case of an empty name field, or ‘Hello Steve’ when I enter my name. Here’s what I get when I print the value of the greeting variable:

Printing description of greeting:
"Hello Steve!"

I’ve disconnected and reconnected the outlet for the label but no joy. Here’s my code:

import Cocoa

class ViewController: NSViewController {

    @IBOutlet weak var nameField: NSTextField!
    @IBOutlet weak var helloLabel: NSTextField!
    override func viewDidLoad() {

        // Do any additional setup after loading the view.

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.

    @IBAction func sayButtonClicked(_ sender: Any) {
        var name = nameField.stringValue
        if name.isEmpty {
            name = "World"
        let greeting = "Hello \(name)!"
        helloLabel.stringValue = greeting


EDIT: I figured it out. I had selected the label, then Edit > Resize to Fit Content, thinking it would automatically resize the field to fit whatever content would be in the field, now or in the future. Bad thinking. Resized label to be full screen width and all is well. It just ended up that it was truncating the text right after ‘Hello’ which threw me.

Good catch! Part 2 of this series will go into auto-layout but this part just used preset object sizes.

Very helpful tutorial but I am having one problem following it in the section mentioning “Go back to Main.storyboard and click on the button to select it. In the Utilities panel on the right, make sure the Attributes Inspector is showing – the 4th button across the top.”

The problem I have is that Main.storyboard opens in a separate window, and when I click on the View Controller, the Attributes Inspector panel of the main XCode window just says “Not Applicable”. I am not sure how to resolve this.

I have recently upgraded to MAC OS Sierra and I got this error “Mac app that is damaged and can’t be opened”. Anyone knows how to resolve this error?

If you have the storyboard open in a new window, you need to show the Attributes Inspector in that window to be able to select and edit UI elements.

Select your Main.storyboard window and in the menus, choose View/Utilities/Show Utilities or use the Command-Option-0 shortcut (zero, not O).

Then you can select the View Controller and edit its attributes in that separate window.

I am a bit confused as to how you could get this error with an app you have built yourself from Xcode. It is a misleading error message that usually indicates macOS’s security is blocking the app from running.

The sample project does not code sign the app, but I thought that apps you build yourself in Xcode were exempt from these restrictions.

Try right-clicking on the app and selecting Open to see if that can bypass the security settings, after a confirmation dialog.

One other possible fix is to go to System Preferences - Security & Privacy. In the General tab, change the “Allow apps downloaded from:” setting to “App Store and identified developers”.

Hi sarah.

I need to learn Swift for development in Macbook.

so I saw your lesson,
“macOS Development for Beginners: Part 1”

I need to buy a book included this lesson.
Which book do i have to buy? plz let me know.

from Wilshire/Vermont.

This tutorial is not included in any book, but you can buy any of the Ray Wenderlich books here: https://store.raywenderlich.com

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]

This was updated on Jun 14, 2021 by @robertomachorro, so reopening comments! :]