Roobiq / RBQFetchedResultsController

Drop-in replacement for NSFetchedResultsController backed by Realm.
MIT License
477 stars 70 forks source link

Swift 3 #103

Closed phatblat closed 7 years ago

phatblat commented 8 years ago

Ran the Swift 3 migration tool and updated the RealmSwift API for the changes in master.

Dependendencies now integrated using CocoaPods instead of git submodules

Fixes phatblat/RBQFetchedResultsController#1

bigfish24 commented 7 years ago

Ok will look into, I am sure I can find a way to convert between the types.

phatblat commented 7 years ago

Too bad Realm isn't casting to RLMObjectBase as it's a common super class.

screen shot 2016-12-01 at 2 38 23 pm

RealmSwiftObject == RealmSwift.Object

phatblat commented 7 years ago

What's the reason that these cache objects extend RLMObject? Seems like they aren't part of the schema and don't need to be persisted, just stored temporarily in memory.

phatblat commented 7 years ago

Nevermind. I see now that they are being stored in a cacheRealm.

bigfish24 commented 7 years ago

This is actually an odd bug because typically at Realm we don't recommend to mix ObjC and Swift together, so the ObjC class definition actually doesn't play nice with the objectTypes getter in the Realm Swift framework. However, what's ironic is that you wouldn't actually hit this when using RBQFetchedResultsController as a framework because the cache object models would be isolated in the framework.... however, in the Swift example the files are included directly in the project!

bigfish24 commented 7 years ago

Ok this is really ugly but using Swift's limited reflection here is how I could get around it:

// Hack to get around issue with cache objects appearing in Realm
// when building RBQFRC not as a framework
let mirror = Mirror(reflecting: configuration)
for child in mirror.children {
    if "customSchema" == child.label {
        let customSchema = child.value as! RLMSchema

        let schemaSubset = customSchema.objectSchema.filter({ (objectSchema) -> Bool in
            let cacheObjectNames = ["RBQControllerCacheObject",
                                    "RBQObjectCacheObject",
                                    "RBQSectionCacheObject"]

            if cacheObjectNames.contains(objectSchema.objectName) {
                return false
            }

            return true
        })

        rlmConfiguration.objectClasses = schemaSubset.map { $0.objectClass }
    }
}
bigfish24 commented 7 years ago

With my change this should be good to go to merge 👍

bigfish24 commented 7 years ago

We can remove this hack once a new release of Realm Swift is released that exposes converter functions to support interoperability of Swift and ObjC Realm objects: https://github.com/realm/realm-cocoa/blob/master/RealmSwift/ObjectiveCSupport.swift#L139-L147

jpsim commented 7 years ago

Barring surprises, we're planning on releasing Realm Swift 2.1.1 today.

jpsim commented 7 years ago

2.1.1 is out: https://github.com/realm/realm-cocoa/releases/tag/v2.1.1

bigfish24 commented 7 years ago

Let's get this fix in for backwards compatibility and then update to use new 2.1.1 APIs

phatblat commented 7 years ago

Sounds good

phatblat commented 7 years ago

LGTM. Thanks everyone for helping with this long-running PR!

bigfish24 commented 7 years ago

👏🎉🎉