Adding Swift to an Objective-C Project

Now that you have a small Objective-C project working, it is time to add some Swift files. Imagine, for example, that you have an epiphany: It would be far better not to hardcode your contacts as strings in an array. Instead, you could create a Contact type and then display the contacts’ names in the table. You decide to use Swift for your new type because you heard how safe its initialization process is, and you want to take advantage of it.

Add a new Swift file to your project. Click FileNewFile.... In the window that pops up, make sure iOS is selected at the top. Select Swift File under the Source label and click Next (Figure 28.11).

Figure 28.11 Adding a new Swift file

In ...

Get Swift Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.