Re: Core Data sync between iOS and Mac apps
Re: Core Data sync between iOS and Mac apps
- Subject: Re: Core Data sync between iOS and Mac apps
- From: Michael Swan <email@hidden>
- Date: Thu, 07 May 2015 10:57:05 -0400
Dave,
Unfortunately on the OS X side with iCloud, Core Data, and documents it is pretty much a pick any two situation. The iOS side can be done but there are some gotchas not really covered in the documentation. I've actually just started work on my own custom subclasses of UIManagedDocument and NSDocument (NSPersistentDocument is less than useless if you want to share with iOS). My current plan is to use Apple's code as much as possible without adding extra stores like Ensembles does. If you're interested we could talk about a collaboration to build an open sourced set of classes to handle this area. (I plan to include a file browser for iOS as well since nothing currently exists.)
On iOS you set two keys in the options dictionary to tell the system where to keep the change logs and what the name should be. The name is typically a UUID and the location is generally some version of ChangeLogs at the root level of the ubiquity container. The catch is that your can't set those options in configurePersistentStoreCoordinator… and have it come out right. You have to init the document then set the persistentStoreOptions property to a dictionary with those keys in order for the file package to get the right structure. You also need to create the document locally first and then move it to the ubiquity container.
On OS X NSPersistentDocument can only make flat files, not packages like UIManagedDocument (I've filed a bug about there being no counterpart to UIManagedDocument for OS X, been open for over a year now…). BSManagedDocument will create a file package that looks like a locally stored UIManagedDocument but it doesn't have the logic for dealing with files in iCloud (my current plan is to build a subclass of BSManagedDocument with the extra logic in place).
Apple's answer to me when I have asked about this in he past is that it is possible to sync Core Data documents through iCloud but you have to do all the heavy lifting (I have no idea if that will change in June, but I doubt it).
As far as entitlements go you just need the document option enabled and to ensure that both apps use the same container.
On the Mac the documents should show up in the normal open sheet just like they do for TextEdit and Preview documents that are in the cloud.
These guides are a good starting point:
Document Based App Programming Guide for Mac
Document Based App Programming Guide for iOS
iCloud Design Guide
iCloud Programming Guide For Core Data
Thanks,
Mike Swan
ETCP Certified Entertainment Electrician
347-451-5418
theMikeSwan.com
> On May 5, 2015, at 8:54 PM, email@hidden wrote:
>
> Message: 3
> Date: Tue, 05 May 2015 17:31:23 -0400
> From: email@hidden
> To: CocoaDev <email@hidden>
> Subject: Core Data sync between iOS and Mac apps
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=us-ascii
>
>
> I'm looking into options for building an iOS and Mac app that can sync/share Core Data between them. I'm well aware of the issues with Core Data iCloud syncing in iOS 5 and 6 and that it is supposedly better so I'm willing to try it. The apps can have deployment targets of iOS 8 and greater and OS X 10.10. I don't expect they'll be ready to release before iOS 9 and 10.11 (or whatever it's called) are out. The apps will be "document-based" in that the user can open different data files each which should sync separately.
>
> The most detail explanation I can find of iCloud Core Data syncing is WWDC 2013 session 207 (which apparently also applies to iOS 8) and the objc.io issue: http://www.objc.io/issue-10/icloud-core-data.html
>
> I looked into Ensembles (http://www.ensembles.io) a bit last year and bought a "support package. I'm also aware of BSManagedDocument (but haven't tried using it). And I've seen this http://ossh.com.au/design-and-technology/software-development/ but I didn't see any accompanying code.
>
> I'm comfortable with Objective-C, Swift, and Core Data locally, but not syncing Core Data.
>
> Is there someone where that I should look for that describes the steps in detail including setting the proper entitlements, etc. in Xcode 6?
>
> I assume now that the iOS synced data would show up in the iCloud Drive on the Mac - correct - or am I missing something that it is only for iCloud Documents, not Core Data sync? I don't quite understand how URLForUbiquityContainer comes into play on the Mac if the files now appear local on the Mac. After the user chooses File -> Open would they navigate to the iCloud Drive and select the file? If so, how does the code then use URLForUbiquityContainer.
>
> Pointers to any documentation or tutorials or recommendations would be appreciated.
>
> Thanks,
> Dave Reed
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden