Xcode 10.2 Swift 5: dynamic' property '' must also be '@objc'

1.8k Views Asked by At

After updating my Xcode to 10.2 which includes Swift 5, I tried building my project and got this error.

dynamic property 'openingHours' must also be '@objc'

on this line of code

dynamic let openingHours = List<ShopHourRealm>()

And before updating to Xcode 10.2, I was able to build and compile my project without any error. Any thoughts why this is happening?

1

There are 1 best solutions below

0
On BEST ANSWER

You don't need to specify dynamic for Realm List types. Just

let openingHours = List<ShopHourRealm>()

will suffice.

Based on the examples here https://realm.io/docs/swift/latest/#models

import RealmSwift

// Dog model
class Dog: Object {
    @objc dynamic var name = ""
    @objc dynamic var owner: Person? // Properties can be optional
}

// Person model
class Person: Object {
    @objc dynamic var name = ""
    @objc dynamic var birthdate = Date(timeIntervalSince1970: 1)
    let dogs = List<Dog>()
}