O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating the Model Layer

In this section, you are going to create a new file that will contain the code that creates a random string. The MainWindowController will receive input from the view layer (a click of the button), call a function in the model layer to do the real-world work (generate a random string), and then update the view layer (display the string in the text field).

In the project navigator, Control-click the RandomPassword group and select New File.... From the Source section under OS X, choose Swift File (Figure 1.26). Save the file as GeneratePassword in the default location.

Figure 1.26  Creating a new Swift file

Xcode will open the GeneratePassword.swift file. At the top of the file, add an array named ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required