user2749170
user2749170

Reputation: 3

Custom initializer with objects

Class UserLaunch: Object{

var launch: Class1
var payload: Class2

init(launch: Class1, payload: Class2){
    self.launch = launch
    self.payload = payload
}

What is the best way to create custom initializer for Realm object? (This one isn't working, because Realm wants default init() method)

Thanks!

Upvotes: 0

Views: 267

Answers (1)

bcamur
bcamur

Reputation: 894

If you can give some default value to the properties this should work (it works for me at least):

class UserLaunch: Object{

    dynamic var launch: Class1 = Class1() //or some other default value
    dynamic var payload: Class2 = Class2() //or some other default value

    convenience init(launch: Class1, payload: Class2){
        self.init()
        self.launch = launch
        self.payload = payload
    }
}

Upvotes: 2

Related Questions