A newcomer to Swift, I have created an NSObject
class, item.h
in a separate file to keep track of my items. Each item has assorted properties.
In Objective-C, I would have just declared the properties as
@property(nonatomic) NSString *name;
and so forth in the interface file.
I have tried to create something similar in Swift as follows:
import UIKit
class item: NSObject {
var topSpeed: Double
var aStrProperty: String
var anIntProperty: Int
}
However, I am getting error: Class 'item' has no initializer
. In the Apple docs, they seem to suggest creating a struct but I was hoping the NSObject
would be the object for my items as I have customarily done in Objective-C
Would appreciate it if someone could explain the right way to give my object properties.
Thanks in advance for any suggestions.