iOS & Swift

macOS Apprentice

If you've always wanted to write your own native macOS apps, this is the book for you! Learn to build beautiful and functional native apps. By Sarah Reichelt.

Read for Free with the Personal Plan* * Includes this and all other books in our online library See all benefits
Buy Individually $59.99 $29.99* *Includes access to all of our online reading features.
Leave a rating/review
Download materials
Buy paperback—Amazon Comments
Save for later
Share

Who is this for?

This book is for developers who are new to Swift and developing in the Apple ecosystem.

Covered concepts

  • Using Xcode
  • Coding in Swift
  • Designing and developing user interfaces with SwiftUI
  • Designing and developing user interfaces with AppKit
  • Using Cocoa bindings to connect data to the user interface
  • Combining SwiftUI and AppKit in the same app

macOS Apprentice is a series of multi-chapter tutorials where you’ll learn about developing native macOS apps in Swift, using both SwiftUI — Apple’s newest user interface technology — and AppKit — the venerable UI framework. Along the way, you’ll learn several ways to execute Swift code and you’ll build two...

more

Before You Begin

This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.

Section I: Getting Started

Begin your journey by learning how to install Xcode and the basics of programming in Swift. Along the way, you’ll learn several different ways to execute Swift code.

1
Toggle description
Ensure your tools are working so nothing slows you down when you dive into this book. Install Xcode and create a new project to take a quick tour of Xcode and Swift basics. You'll learn some tips for using Xcode efficiently.
Toggle description
Start finding your way around Swift by running it in Terminal. Learn about Swift's data types, operators, variables, constants and collections.
Toggle description
Use Xcode to build a command line app that runs in Terminal. Learn more Swift features including conditionals, loops, functions and optionals.
Toggle description
Use a Swift Playground to learn how to combine Swift types and functions into your own custom types.

Section II: Building With SwiftUI

In this section, you’ll use Apple’s newest user interface technology — SwiftUI — to develop a word-guessing game called Snowman. You’ll learn about data flow in SwiftUI, managing multiple windows, using charts and adding macOS-specific features such as toolbars and menus.

Toggle description
Start building a full app using SwiftUI. Design and implement the layout using SwiftUI components.
Toggle description
Start adding real data to the user interface. Learn about SwiftUI data flow and property wrappers.
Toggle description
Learn more about data flow in SwiftUI and how to send data to all parts of your app. Make an observable object that's available to all your views.
Toggle description
Learn more about operating with multiple windows in your app. Add a Settings window for user preferences and a completely new view window.
Toggle description
Use the SwiftUI Charts library to display your game statistics in a more interesting format.
Toggle description
Mac users expect their apps to look and operate consistently. In this chapter, you'll add a toolbar to the main window and customize the menus to suit your app. Finally, you'll add an icon and export your app.

Section III: Building With AppKit

From the very beginning of macOS X, AppKit has been the workhorse behind the user interface of all apps and there are still a number of tasks where it is the superior choice. In this section, you’ll explore such an area while building an app to browse movie data from IMDb, the online movie database.

Toggle description
Use AppKit to create a new app. Learn what AppKit is and use AppKit tables to display movie data.
Toggle description
Select movies in the table to show their details. Design a more complete user interface using the storyboard and Auto Layout. Mark your favorite movies.
Toggle description
Add more features to the table. Sort and search the list. Save and reload your edited data. Learn about the Mac sandbox.
Toggle description
Menus are an important part of the user experience for any Mac app. Edit existing menus and add your own. Create a contextual menu. Add an app icon and display the table status.
Toggle description
Add a new window to edit a movie. Set up the user interface for the new window. Pass data to and from it. Configure the view using Auto Layout.
Toggle description
Set up the data flow for the edit window using Cocoa Bindings. Learn the different methods of working with data in AppKit views.

Section IV: Combining SwiftUI & AppKit

Apple has made it simple to include pieces of both user interface frameworks in a single app. In this section, you’ll do just that in order to add some finishing touches to both of the apps from the previous sections.

Toggle description
SwiftUI can't do everything, so you'll learn how to integrate AppKit features into a SwiftUI app and when this is a good approach.
Toggle description
In a reverse of the last chapter, add SwiftUI elements into an AppKit app. When is this the right way to build an app?