2

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?

Shabir jan
  • 2,295
  • 2
  • 23
  • 37

1 Answers1

4

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>()
}
jabeattie
  • 56
  • 4