Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

es9900

macrumors newbie
Original poster
Jul 21, 2016
2
0
I am trying to figure out how to setup CloudKit for an OS X app. There’s very little documentation and Apple’s examples are coded in Objective C.

So far I did the following:


1) Create a new Xcode project

2) Choose OS X > Application > Cocoa Application

3) Gave project a product name of “MyTestCloud”, used Swift for the language and only checked “Use Storyboards”

4) Set “Signing” to the “Mac App Store” and set “Team” to my team

5) Under “Capabilities” I turned on “iCloud”, for “Services” I checked “Key-value storage” and “CloudKit” (I used the default container)

6) Added a “Wrapping Text Field” to my storyboard

7) Create an outlet for my “Wrapping Text Field” and called it “myTextField”

What I want to be able to do with CloudKit is sync whatever is being added to the text field with CloudKit. I want to sync it as the user enters the text. I want to use the private area of CloudKit.

I also want to create a subscription so if the text is changed on another Mac it automatically updates in real time on the other Mac.

I also want to cache the text (in case the user doesn’t have an Internet connection at that moment).

Lastly, how would I handle conflicts? Say the user changes the text when offline and then changes it again on a different offline Mac — how would the program know which is newest - is this built into CloudKit?

Any help would be much appreciated. I spent the last week Googling this and could not find an example of CloudKit for OS X written in Swift that dealt with private data. I think this is probably pretty simple but I don’t know where to start.

Any help would be much appreciated. Thank you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.