Monday, April 27, 2015

Week 1 With Ensembles

My goal this week was to build a stack to have Core Data on the local device and use Ensembles to sync the data to iCloud.  I’m not finished yet.

Progress
After reading 100 pages in the Ensembles book I felt I was ready to go.  I quickly learned I needed an example to make much progress.  I opened up the Idiomatic Example application and worked through it.  I’m a little stuck on the use of the container id.  It is unclear to me what I am supposed to use for the ubiquity container Identifier.  Do I use nil as in the idiomatic example, do I use some arbitrary String as in the simple sync example, or do I use the ubiquity container id as I would with straight CoreData?  I think I am going to try the standard ubiquity container id as I would do if I was using CoreData sync.

A second issue I ran into was how to implement persistentStoreEnsemble(ensemble: CDEPersistentStoreEnsemble!, globalIdentifiersForManagedObjects objects: [AnyObject]!)
in Swift. I’m not sure what I will do with this yet.

I posted the problem I was talking about in last weeks post with my CoreData solution to the Apple CoreData forums.  I’m not sure whether no one understood what I was asking or no one has an answer.  But at any rate, its been four days since my post and NO ONE has responded, although I know it has been looked at.  Hmm, I wonder if there is a problem here :-)

Looking back at my CoreData+Sync solution it appears that I might have a threading issue.  I’ve also decided I am going to relook at Parse or CloudKit.  So it looks like I have three test apps in play right now:

CoreData + iCloud Sync - My plan here is to relook at the threading concerns to see if maybe that is the real culprit here.

CoreData + Ensembles - For this one I need to put some more code down before I can start testing.

Parse/CloudKit - I don’t have a test project for this yet, but having worked with it in the past it seems like it won’t be too bad.  I just need to find time to do it.

Reading
I’m over halfway through Spring in Action now.  I have a test app working with both login and logout and a few protected and unprotected web pages.  I just finished the section on persistence.  I’ll probably go with a standard SQL solution for that as I am most comfortable with that type of a solution.

News That Caught My Eye
I watched the keynote from RubyConf 2015 this week.  They introduced Rails 5.  It looks like the Rails community is still thriving.  The big question in my mind is do I continue to use Rails and bring my web apps into the new version, or do I swing back to my Java roots and convert to Spring solutions.  

Quick Looks

I looked briefly at Realm for my iOS applications this week.  It is very interesting and I really want to use it, but I think I would need to stand-up my own server for cross device syncing.  I think that is where I ultimately will end up for all my solutions, but right now I need to get the current test apps done.   

2 comments:

  1. Hi!

    After many weeks lost to iCloud + Core Data sync, I'm getting started with Ensemble, but today I crashed against "func persistentStoreEnsemble(ensemble: CDEPersistentStoreEnsemble!, didSaveMergeChangesWithNotification notification: NSNotification!)", I have no idea how to implement this in Swift, and I've found this post.

    May I ask for help? How did you manage to implement it in Swift?

    ReplyDelete
    Replies
    1. For me this method was very simple. I have an object that holds the entire stack including the main NSManagedObjectContext which I call mainQueueMOC. Having said that, here is the method I have:

      func persistentStoreEnsemble(ensemble: CDEPersistentStoreEnsemble!, didSaveMergeChangesWithNotification notification: NSNotification!) {
      if let mainQueueMOC = mainQueueMOC {
      // merge the changes in the notification into the main MOC
      mainQueueMOC.performBlockAndWait() {
      mainQueueMOC.mergeChangesFromContextDidSaveNotification(notification)
      }
      }
      }

      Yeah, I know, it is a blocking call, but at the time I wasn't worried about performance. I wonder if the issue you are having is related more to the handling of the notification. I was just writing up my walk-through of my Ensembles test app and I noticed how some of the notifications are being handled. I should have my walkthrough posted in the next couple of days, so maybe seeing the whole picture might help.

      Delete