caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.93k stars 243 forks source link

Generic class 'SyncObject' requires that 'String' inherit from 'RealmSwiftObject' #266

Open mibrahim025 opened 1 year ago

mibrahim025 commented 1 year ago

Hi all, I am using icecream library and want to achieve the following functionality.

In app delegate, I have written

syncEngine = SyncEngine(objects: [
            SyncObject(type: Recipient.self, uListElementType: String.self),
            SyncObject(type: SMSSchedule.self, uListElementType: Recipient.self),
            SyncObject(type: Template.self),
            SyncObject(type: ContactsGroup.self, uListElementType: Recipient.self)
        ])

where Recipient class is...

@objc class Recipient: Object {

    @objc dynamic var rec_id = ""
    @objc dynamic var firstName = ""
    @objc dynamic var lastName = ""
    var phoneNumbers = List<String>()
    @objc dynamic var email = ""
    @objc dynamic var colorTag = "#FFFFFFFF"
    @objc dynamic var isDeleted = false  // IceCream requirement

    override static func primaryKey() -> String? {
        return "rec_id"
    }

// initialization code

}

Look at the phoneNumbers property. It is a list of string objects. However the SyncObject doesn't accept String as uListElementType. How can I solve this issue?

andresitsu commented 1 year ago

String is not an object. You only put realm objects as uListElementType.

Actually you don't need to do anything regarding List of supported primitive types ( Int, String etc.)