caiyue1993 / IceCream

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

Cannot find type 'ListBase' in scope #267

Open wawilliams003 opened 1 year ago

wawilliams003 commented 1 year ago

Hello, I am getting this error after updating to the latest version of ICream. I am using Cocoapods on Xcode 14.0, with swift 5. RealmSwift (10.8.1) IceCream (2.0.2)

public var record: CKRecord {
        let r = CKRecord(recordType: Self.recordType, recordID: recordID)
        let properties = objectSchema.properties
        for prop in properties {

            let item = self[prop.name]

            if prop.isArray {
                switch prop.type {
                case .int:
                    guard let list = item as? List<Int>, !list.isEmpty else { break }
                    let array = Array(list)
                    r[prop.name] = array as CKRecordValue
                case .string:
                    guard let list = item as? List<String>, !list.isEmpty else { break }
                    let array = Array(list)
                    r[prop.name] = array as CKRecordValue
                case .bool:
                    guard let list = item as? List<Bool>, !list.isEmpty else { break }
                    let array = Array(list)
                    r[prop.name] = array as CKRecordValue
                case .float:
                    guard let list = item as? List<Float>, !list.isEmpty else { break }
                    let array = Array(list)
                    r[prop.name] = array as CKRecordValue
                case .double:
                    guard let list = item as? List<Double>, !list.isEmpty else { break }
                    let array = Array(list)
                    r[prop.name] = array as CKRecordValue
                case .data:
                    guard let list = item as? List<Data>, !list.isEmpty else { break }
                    let array = Array(list)
                    r[prop.name] = array as CKRecordValue
                case .date:
                    guard let list = item as? List<Date>, !list.isEmpty else { break }
                    let array = Array(list)
                    r[prop.name] = array as CKRecordValue
                case .object:
                    /// We may get List<Cat> here
                    /// The item cannot be casted as List<Object>
                    /// It can be casted at a low-level type `ListBase`
                    -------ERROR ON THIS LINE BELOW----------
                    **guard let list = item as? ListBase, list.count > 0 else { break }**
                    var referenceArray = [CKRecord.Reference]()
                    let wrappedArray = list._rlmArray
                    for index in 0..<wrappedArray.count {
                    ---- AlSO THIS ERROR ON LINE BELOW : -- Type of expression is ambiguous without more context -- 
                        guard let object = wrappedArray[index] as? Object, let primaryKey =     object.objectSchema.primaryKeyProperty?.name else { continue }
andresitsu commented 1 year ago

You may use the most updated version of Realm by switching to Leon's forked IceCream (see Pull Request), which solved this issue.