Search code examples
iosmysqldatabase2d-gamescloudkit

CloudKit for my iOS game


I'm creating iOS game where users can create some record and store it on server(currently it's just my own server with simple SQL DB). Next, anyone can get records by ID of any object stored on my server. My current database fields:

  • ID unique auto-generated
  • objectDATA: data of user created object. It's just base64 string, but typical size varies from 50Kb to 3Mb.
  • NAME: short name, user specified, string.
  • IMG: png image file that shows preview of user created object. Typical size up to 100Kb.

After record created: it can't be deleted or modified in any way. Any record can be retrieved from any device where game installed just by - id. If user tries to save a duplicate record - server just returns id of already stored record. Duplicate determined by comparing objectData value before writing to DB.

My questions are:

  1. Is such behavior can be done in the CloudKit?

  2. Where I can find some good example tutorial(in Objective C) that shows me hot to work with CloudKit and store records as I described? Or maybe someone can help with code snippets?

Probably, duplicates can't be checked, but it's okay... My main goal - implement reading and writing to CloudKit.

Also, is there any limits of size? I'm worry about objectDATA fileld...


Solution

  • Yes, all that could be done using CloudKit. I think you should store the objectDATA in a CKAsset field in CloudKit. Then there are no size limitations at all. You definitely would like to store the IMG in a CKAsset.

    The total size of a record’s data is limited to 1 MB though assets do not count against that limit.

    When you do start using CloudKit for an app, then you will get 5GB of data for free plus 100MB per user of your app.

    Apple has a nice demo app that will show you most of your requested functionality. Just have a look at the CloudKit Atlas demo at: https://developer.apple.com/wwdc/resources/sample-code/

    If you are planning to use Swift as a programming language (which I can advice) then have a look at: https://github.com/evermeer/EVCloudKitDao