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 File → New → File.... 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access