Hi! I've design my models that implements singleton patterns with sharedInstance.
class Car {
static let sharedInstance = Car()
}
How can I implement singleton pattern using sharedInstance in ObjectMapper class? When I'm working with sharedInstance and Mappable. This cause a error like _Missing argument for parameter 'map' in call_
class Car: Mappable {
static let sharedInstance = Car()
var mode: String?
required init?(map: Map) { }
func mapping(map: Map) {
mode <- map["info"]["mode"]
}
}
Just add an initializer:
class Car: Mappable {
static let sharedInstance = Car()
var mode: String?
+ init() {
+ self.mode = nil
+ }
required init?(map: Map) { }
func mapping(map: Map) {
mode <- map["info"]["mode"]
}
}
Another alternative would be to look into the StaticMappable protocol (see README)
Thank you so much @tristanhimmelman and @devxoul
@anddygon what does that mean?
@anddygon what do you want?
Adding an empty initializer solves the problem.
init() {
}
Most helpful comment
Just add an initializer: