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