If you are using Swift 4, you need to change the declaration of the Contact class to include @objcMembers as follows:
@objcMembers class Contact: NSObject {
let name: String
init(name: String) {
self.name = name
super.init()
}
}
If you don’t do this, you will get a bunch of errors stating “No visible @interface for ‘Contact’ declares the selector ‘initWithName:’”
You can verify that this is the problem by examining the Contacts-Swift.h file which Xcode puts in the DerivedData directory for your project. To find this file, find your project directory in
/Library/Developer/Xcode/DerivedData. You can then search this directory using Terminal with the following command:
find * -iname '*Swift.h'
On my computer, the file was located in:
<project directory>Build/Intermediates.noindex/Contacts.build/Debug-iphonesimulator/Contacts.build/DerivedSources/Contacts-Swift.h