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 ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.