Reputation: 99
I'm using Ensembles in this project where I have different user-groups stored under separate directories. I've built this more or less copying the example app, Idiomatic's sync-manager.
Initialising the CDECloudFileSystem i do this:
newSystem = [[CDECloudKitFileSystem alloc] initWithUbiquityContainerIdentifier:[CKContainer defaultContainer].containerIdentifier
rootDirectory:directoryString usePublicDatabase:YES];
Where the directoryString is the global ID of the current user-group.
Now I'd like to be able to switch between groups, letting the users only have their group's data locally on the device.
My idea how to solve this is to change user-group by selecting it from a table view (a bunch of CKRecords with the group's name and global ID corresponding the Ensembles/Core Data objects), deleeching to remove old data in case the user is logged into a different group, and then leeching to get the data of the selected group.
Would this method work, will the old data be deleted locally on a deleech or are there better ways to go about this?
Upvotes: 1
Views: 447
Reputation: 3592
I think your plan sounds OK. The main challenge will be how you are going to manage how a user joins a particular group.
Note also that the public DB is entirely public. Something that may be of interest is that there is now an option for encrypting data with a password. It has just been added to github. You could use a password to conceal the data of each group.
Deleeching just deletes the cache of sync data. It does not remove your local persistent store data. If you leech again, the local data would import again. If you don't want that, you will have to remove the persistent store, delete the store files, and add back an empty store.
You should also check the leech options. There is one that assumes all data is in the cloud, and that should be more efficient for your case.
Upvotes: 2