0

My plan is to purchase Ensembles 2 (to take advantage of speed/efficiencies etc) but am trying to make sure that I will be able to get it to work (in a test Swift project) first. To do this I am experimenting with v1.

Using the Simple Sync with Swift as a guide I have incorporated ensembles into my xcode project.

The data from the app does appear to be getting stored in iCloud as when I delete the app and then re-add it, leeching and then syncing does restore the correct data from iCloud. My trouble is that testing with a second device (signed in to the same apple/iCloud account) does the same thing with its own data. The data from the 2 devices is never merged. However the data created on each device is restored to its own device after reloading the app.

Does anyone know how this could be?

Am wondering if the problem might be the store url that I am generating. A lot of the Core Data Stack set up is now done automatically in Swift 3+ (NSPersistentContainer) and so these things do not need to be generated by the user. Here is how i am generating the variables for store url and model url to use when setting up my ensemble:

var storeDirectoryURL: URL {
        return try! FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
    }

var storeURL: URL {

        return storeDirectoryURL.appendingPathComponent("VsSyncTest.sqlite")
    }

    // Setup Ensemble

let modelURL = Bundle.main.url(forResource: "VsSyncTest", withExtension: "momd")
mallowman
  • 211
  • 1
  • 3
  • 9

1 Answers1

0

The only way I can imagine that would happen is if either you are using different iCloud accounts, or you have a different ensemble identifier for each device.

Note also that the iCloud document sharing can be stubborn. Just because the files get added to the container locally does not mean they will immediately transfer to the other device. (CloudKit backend is much better in that respect, but only in E2.)

If you are testing with the simulator, using Debug > iCloud > Trigger Sync in Simulator may help.

Drew McCormack
  • 3,490
  • 1
  • 19
  • 23
  • Thanks Drew. The iCloud account is definitely the same (have signed out and in again on each). As is the ensembles identifier (have deleted from both devices and reloaded from xcode). Forcing a sync on the simulator has not helped either. Is there anything else that I could do? Is there a way to see what is stored on iCloud as that might give some idea about what is going on? – mallowman Oct 26 '17 at 18:46
  • My best guess is that you are simply not calling the `merge...` method. No cloud data will be brought in unless you call `merge...`. Add a button or a timer to do that (notifications work, but not reliably). To check container content, go to `~/Library/Mobile Documents/iCloud~`. On a Mac, just in your home folder, and in simulator, locate the user folder and go from there. – Drew McCormack Oct 27 '17 at 08:19
  • Explicitly calling merge isn't making any difference. Am wondering if maybe my persistentStore: store url is wrong and that a different one is being used on both devices. Is that possible? The latest versions of Swift/xcode do a lot of the setting up of the Core Data stack behind the scenes and so not sure if i am pulling the correct url. Will edit question with code.... – mallowman Oct 27 '17 at 12:58
  • There must be some issue currently with using the simulator to test syncing via iCloud. Have been able to test now on 2 physical devices and sync works as expected. – mallowman Oct 30 '17 at 14:31