Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 3 #103

Merged
merged 54 commits into from
Dec 5, 2016
Merged

Swift 3 #103

merged 54 commits into from
Dec 5, 2016

Conversation

phatblat
Copy link
Collaborator

@phatblat phatblat commented Jul 3, 2016

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#1

Pointing to phatblat/swift-3 branch
warning: FetchedResultsController.swift:93:198: Extraneous duplicate parameter name; 'newIndexPath' already has an argument label
@phatblat
Copy link
Collaborator Author

phatblat commented Jul 6, 2016

Strange build issue is resolved in Xcode 8b2 (8S162m) 🎉

@RyanCodes
Copy link

What is the status of this PR? Will this be released soon?

@bigfish24
Copy link
Contributor

Sorry I will try to pick up on this next week. Realm is announcing something new next week and I have been heads down all summer.

@cezarywojcik
Copy link

@phatblat @bigfish24 any ETA on the Swift 3 support?

@syky27
Copy link

syky27 commented Oct 14, 2016

Can someone take a look at this perhaps?

Thank you for support!

@syky27
Copy link

syky27 commented Oct 27, 2016

Ok, It seems that no one is willing to merge this.

@phatblat Thank you very much for this update, I was unfortunately unable to get this working with your forked pods, could you point me to correct way how to get this working temporarily?

Thank you

@phatblat
Copy link
Collaborator Author

@syky27 You can install an unreleased version of a pod from a branch using the following:

pod 'RBQFetchedResultsController', git: 'https://github.com/phatblat/RBQFetchedResultsController.git', branch: 'swift-3'

@phatblat
Copy link
Collaborator Author

Almost forgot, since RBQSafeRealmObject is a dependency of this library and its Swift 3 migration is still (in-progress](Roobiq/RBQSafeRealmObject#2), you'll want to include it from a branch as well, but that dependency should be before RBQFetchedResultsController, so that it uses the modified version instead of a released version.

pod 'RBQSafeRealmObject', git: 'https://github.com/phatblat/RBQSafeRealmObject.git', branch: 'swift-3'
pod 'RBQFetchedResultsController', git: 'https://github.com/phatblat/RBQFetchedResultsController.git', branch: 'swift-3'

@bigfish24
Copy link
Contributor

@phatblat and @syky27 sorry this has sat idle for so long. Not much I can say other than I sincerely apologize. Added @phatblat as a contributor to both repos... if things are ready do you want to merge, if not I can do so too?

@syky27
Copy link

syky27 commented Oct 27, 2016

Well this is getting better, @phatblat I was trying that exactly as you suggested now, but I still could not build because some error, and now when I wanted to give you the error, cocoapods are acting crazy, I need to do gem cleanup in a sec, cannot really do it now... I will keep you posted.

@bigfish24 Sorry for being such pain in the ass.

@bigfish24
Copy link
Contributor

bigfish24 commented Oct 27, 2016

Sorry for being such pain in the ass

Not in the slightest! This is entirely my fault and I should have addressed it far sooner.

@syky27
Copy link

syky27 commented Oct 27, 2016

@phatblat So I fixed my cocoapods installation the build error I am getting is:

/Users/syky/optify/optify-ios/Pods/RBQFetchedResultsController/RBQFetchedResultsController/Source/CacheObjects/RBQObjectCacheObject.h:10:9: 'RBQSafeRealmObject.h' file not found

In RBQObjectCacheObject.h file.

@phatblat
Copy link
Collaborator Author

@syky27 do you have use_frameworks! In your Podfile? That import needs to be changed to work with frameworks/modules. I'll update it tomorrow.

@phatblat
Copy link
Collaborator Author

@bigfish24 thanks for adding me as a contributor! I'll double check my changes, test them in Xcode 8.1 and merge when things look good.

@syky27
Copy link

syky27 commented Oct 31, 2016

Hi, @phatblat did you find a time to get to this?

@syky27
Copy link

syky27 commented Nov 2, 2016

Could someone please merge this? Or at least provide me with solution? @phatblat you said that the import needs to be changed but you did not provide me with solution.

I know that I am really pressing on this, it's kinda critical for me.

Thank you in advance.

@syky27
Copy link

syky27 commented Nov 22, 2016

And when I build and run the project I am getting SIGABRT in RealmConfiguration.swift:180

With following:

Could not cast value of type 'RBQSectionCacheObject' (0x10e01b560) to 'RealmSwift.Object' (0x10ea16390).

EDIT: Just realizing this is Realm thing.... I will try to update it I might running wrong version.... but shouldn't RBQFetchedResultsController have dependency on Realm, and if so is't it fetching wrong version.... 🤔

-- Runnning Realm 2.1.0

EDIT2: I guess It is too late for my brain it is just not working.... EDIT above is complete nonsense, sorry. The problem is obviously described above. I either cannot read English anymore or my prescription glasses ain't working.

@ccheungfb
Copy link

What are the missing pieces to get this change merged? This is the last piece that our project needs to fully convert to Swift 3 / xCode 8.

@generalpf
Copy link

This PR is the only thing keeping me from choosing Realm for my projects at work and at home. I know, it's open source and all that, but unless Realm has a drop-in replacement for the fetched results controller, it's a really tough sell to the team.

It would be nice if the nice folks at Realm could supply this and not rely on a third-party to provide it.

@phatblat
Copy link
Collaborator Author

phatblat commented Dec 1, 2016

Sorry for the delay in finishing this up. I believe all the changes necessary are done, I just haven't been able to test it to verify that everything is working correctly. I'll plan to merge this tomorrow, allowing one last day for feedback.

@syky27
Copy link

syky27 commented Dec 1, 2016

@phatblat see my last comment I am getting an error

@phatblat
Copy link
Collaborator Author

phatblat commented Dec 1, 2016

Ah, I'm getting the same error when running the "Swift" (no suffix) example project.

Could not cast value of type 'RBQSectionCacheObject' (0x1096e5a98) to 'RealmSwift.Object' (0x10a19e390).

@phatblat
Copy link
Collaborator Author

phatblat commented Dec 1, 2016

It's blowing up in toRLMConfiguration when retrieving configuration.objectTypes in order to copy over to rlmConfiguration.objectClasses. It's trying to cast RBQSectionCacheObject to RealmSwift.Object, but it is a subclass of RLMObject.

It looks like RealmSwift assumes that all objects that are part of the schema will be instances of RealmSwift.Object with no mix-and-match of the objc version of the framework. I hope this doesn't mean all the cache objects need to be reimplemented in Swift.

@bigfish24
Copy link
Contributor

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

@phatblat
Copy link
Collaborator Author

phatblat commented Dec 1, 2016

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
Copy link
Collaborator Author

phatblat commented Dec 1, 2016

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
Copy link
Collaborator Author

phatblat commented Dec 1, 2016

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

@bigfish24
Copy link
Contributor

bigfish24 commented Dec 2, 2016

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
Copy link
Contributor

bigfish24 commented Dec 2, 2016

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 }
    }
}

rlmConfiguration.syncConfiguration = RLMSyncConfiguration(user: syncConfig.user, realmURL: syncConfig.realmURL)
}

if let objectTypes = configuration.objectTypes {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with this for now:

// 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
Copy link
Contributor

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

@bigfish24
Copy link
Contributor

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
Copy link

jpsim commented Dec 2, 2016

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

@jpsim
Copy link

jpsim commented Dec 3, 2016

@bigfish24
Copy link
Contributor

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

@phatblat
Copy link
Collaborator Author

phatblat commented Dec 5, 2016

Sounds good

@phatblat phatblat changed the title [WIP] Swift 3 Swift 3 Dec 5, 2016
@phatblat
Copy link
Collaborator Author

phatblat commented Dec 5, 2016

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

@phatblat phatblat merged commit a861b89 into Roobiq:master Dec 5, 2016
@phatblat phatblat deleted the swift-3 branch December 5, 2016 03:45
@bigfish24
Copy link
Contributor

👏🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants