Search code examples
iosobjective-cswiftrealm

Porting Int Realm List from Objective-c to Swift


How do I porting Realm data model from Objective-c to Swift like below property?

Objective-c

@property RLMArray<NSNumber *><RLMInt> *dates;

Swift (My solution but it's not working)

let dates = List<Int>()

Error

Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=10 "Migration is required due to the following errors: - Property 'MyDataModel.dates' has been made required."


Solution

  • I found that I just had to add requiredProperties method on the RLMObject subclass in Objective-c version, and it will work fine in Swift version. The reason is that the List type must be non-optional.

    + (NSArray<NSString *> *)requiredProperties {
        return @[@"dates"];
    }