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. By Roberto Machorro.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
macOS Development for Beginners: Part 1
20 mins
Do you want to learn how to develop your own apps for macOS?
Good news! Apple makes developing for macOS incredibly easy, and in this tutorial series you’ll learn how. You’ll learn how to create your first app for macOS — even if you’re a complete beginner.
- In this first part you’ll first learn about how to obtain the tools you need to develop for macOS. Then, while creating a simple “Hello, World!” app, you’ll take a tour of Xcode, discovering how to run an app, edit code, design the UI and debug your code.
- In Parts 2 & 3 of this series, you’ll create a more complex Egg Timer app and learn about the components that make up a macOS app, from how an app starts, to constructing the UI, all the way to handling user interaction.
So what are you waiting for? The world of desktop apps awaits!
Note: Here’s some guidance of where to begin with this series:
- If you are new to Swift, this series assumes some Swift knowledge, so first check out our Swift tutorials to get a great introduction.
- If you already have iOS experience, this first part of the series will be a review. Take a quick look through the topics to make sure and then skip straight ahead to the next part of the series.
- Otherwise, keep reading. This series is for complete beginners – no experience of developing for iOS or macOS is required!
Note: Here’s some guidance of where to begin with this series:
- If you are new to Swift, this series assumes some Swift knowledge, so first check out our Swift tutorials to get a great introduction.
- If you already have iOS experience, this first part of the series will be a review. Take a quick look through the topics to make sure and then skip straight ahead to the next part of the series.
- Otherwise, keep reading. This series is for complete beginners – no experience of developing for iOS or macOS is required!
Getting Started
To become a macOS developer, you will need two things:
- A Mac running macOS Big Sur: The macOS operating system only runs on Apple computers, so you need a Mac both to develop and run macOS apps.
- Xcode: This is the IDE used to create macOS apps. You’ll learn how to install this later in this section.
Once you’ve built your app, if you want to upload it to the App Store for distribution, you’ll also need to pay for an Apple developer account. But this is not a requirement until you are ready to send your app out to the world, and even then, only if you want to distribute through the Mac App Store. If you already have a developer account for distributing iOS apps, then you are all set – Apple has merged the developer accounts so that you only need a single account to distribute apps for any Apple devices.
Unlike some other platforms, developing for macOS requires the installation of just one tool: Xcode. Xcode is an IDE (Integrated Development Environment) that includes everything you need to develop macOS, iOS, watchOS and tvOS apps.
If you don’t have Xcode already, click on the Apple icon in the upper left of your menu and select App Store… to open the Mac App Store. You will need an App Store account to download Xcode even though Xcode is free.
Search for Xcode and click the Install button to start the download. Once it has downloaded and installed (which may take a while – it is quite large) open it from your Applications folder. The first time you run Xcode, and after every major update, it will ask you for permission to install additional components. Enter your password and allow Xcode to install these components.
Hello World!
Following the long-standing tradition when learning a new programming language or platform, you are going to start by creating a Hello World! app for macOS.
Open Xcode if it is not already running. You should see a Welcome to Xcode window – if you don’t see it, choose Welcome to Xcode from the Window menu.
Click Create a new Xcode project and when the next dialog appears, choose macOS from the tabs across the top. Select App from inside the Application section and click Next.
Give your new app a name – HelloWorld – make sure Storyboard is selected for user interface and that the language is set to Swift. Uncheck all the other options.
Click Next and Create to save your new app project.
Running Your App
Xcode has created the basic template for your app with all the required files. At this stage, it is fun to run the app and see how much you get for free.
Click the Play button in the toolbar to run the app or use the Command-R shortcut. Xcode will now compile all of the code into machine code, bundle up the resources required by the app and then execute it.
Note: The first time you ever build and run an app in Xcode, you might be asked whether you want to Enable Developer Mode on this Mac. You’re safe to select Enable, at which point you may have to enter your password. Developer mode allows Xcode to attach a debugger to running processes – which will be extremely useful when building your application!
Note: The first time you ever build and run an app in Xcode, you might be asked whether you want to Enable Developer Mode on this Mac. You’re safe to select Enable, at which point you may have to enter your password. Developer mode allows Xcode to attach a debugger to running processes – which will be extremely useful when building your application!
You should now see a blank window but don’t be disappointed – have a look at what you can already do:
- The window is resizable, it can be minimized and made full screen.
- There is a complete set of menus, many of which already work without you doing anything.
- The Dock icon has the usual menus.
But now it’s time for you to make the display a bit more interesting, so quit the app and go back to Xcode.