Question: [![skize](https://i.stack.imgur.com/mORbU.png)](https://i.stack.imgur.com/mORbU.png)

I want to find out how many people rated a specific location. the problem is that my sql ONLY works if the hasVotedLocation table CONTAINS THE ID OF THE SPECIFIC LOCATION. Meaning if nobody voted the specific location i get zero rows.

My sql statement:

```
select count(*),l.idLoc from Location l
left join hasVotedLocation hvl
on hvl.idLoc=l.idLoc where l.idLoc=2
group by l.idLoc 

```

[![d](https://i.stack.imgur.com/8UlqH.png)](https://i.stack.imgur.com/8UlqH.png)

For `idLoc=1` the query should return one row with `count(*)=3 and idLoc=1`

For `idLoc=2` the query should return one row with `count(*)=0 and idLoc=2`

For `idLoc=3` the query should return one row with `count(*)=1 and idLoc=3`

Answer: 
To see the changes with Simulators you have to quit the app, and reload it (or build & run).

Simulators have never been able to receive Remote Notifications to trigger an iCloud sync so you need to manually force a sync, but I've found that syncing cannot be triggered manually from the menu in my Xcode 11 beta (gives an error). 

There is a good post by Andrew Bancroft about some other things such as setting the **automaticallyMergesChangesFromParent** property to true, but this doesn't make a difference when using Simulators (EDIT: It does, but I didn't realise as I was just building & running each time).

Andrew's Post: <https://www.andrewcbancroft.com/blog/ios-development/data-persistence/getting-started-with-nspersistentcloudkitcontainer/#where-s-my-data>

I'm in the same boat as I can't afford to install any beta software (except Xcode) so I'm going to have to stick with the simulators. But my experience of converting an existing App to CloudKit has been very, very positive. I just had to do three things to my existing project:

* **Add Background Notification & CloudKit capabilities**
* **Make sure all Core Data attributes & relationships are optional (or have a default value if nil)**
* **Rename NSPersistentContainer to NSPersistent*CloudKit*Container**

...and that's it! Mind blown.

All my nested many-to-many relationships appear to work perfectly. 

I still need to work out how to sync images currently stored as JPGs in the users Documents directory but I suspect they'll need to be stored in Core Data as BLOBs to enable conversion to CKAssets in the background.
Apple now have example code called CoreDataCloudKitDemo.
This includes all the basic stuff and also has additional code which processes the changes when they arrive from the other device.
You need to have the lines 

description.cloudKitContainerOptions =
 NSPersistentCloudKitContainerOptions(
 containerIdentifier: "iCloud.com.developerid.databasename")

to get your local database going to iCloud and creating the schema.
You need to use the Cloudkit Dashboard on the web to see the schema etc.