AILCKS - Part 2: Keeping Things Simple
I’m building sync for a game called Qiktionary, which is a simple (yet hard) word game. Discover the secret word by guessing other words and using deductive logic. Basically Word Mastermind except at the end of a game of Qiktionary you learn an interesting fact related to that word1.
So the data model is composed of stuff like words, games, guesses, etc. There is also word packs which is just a way for us to logically group words and provide progress in a more interesting way. They look like this:
All this data is stored locally on the device in a SQLite database. I’m using FCModel to simplify the database access as I like the clean and small abstraction over FMDB. The app ships with a seed database that includes all the word packs and words (and a few other things) that is copied on first launch. If that doesn’t work the app also ships with a large plist file that has the word and word pack structured data and the app can import from the plist into the database if need be.
This basic setup works pretty well. As you can see, there is no server involved. Everything is stored locally. When that above list of word packs need to be rendered there is no asynchronous network request to fetch the them, just a simple
SELECT * FROM WordPack2.
I like simple.
Introducing syncing makes this not so simple, which makes me nervous. CloudKit is supposed to be easy, but just because something is easy doesn’t mean it can’t yield a good deal of complexity.
So my goal is to try and keep the complexity to a minimum. To accomplish that I have to do the absolute bare amount of changes to the app as I can. That means I’m only going to sync what I have to.
I could put the words and the word packs in the public iCloud database and use CloudKit to fetch them when needed, but that would change the assumption that the data is just a synchronous database-fetch away. There would be benefits to putting them in iCloud, like the ability to update them without an app release. Maybe in a later release.
I could also build out the Game Center leaderboard and achievement features3 alongside sync but instead I’m doing this CloudKit integration as its own release and so those features will have to wait until sync is implemented (and works reliably).
What I am going to do is:
- Push device Game data to iCloud.
- Pull Game data from iCloud and put it on the device.
- Associate Game data with a Game Center player
Hopefully that is simple enough that even I can’t screw it up.
Watch out for Part 3 where I’m probably going to screw it up.
Be notified of new posts by following me on Twitter.
The facts are courtesy of the QI Elves, a group of devishly smart people who write all the funny stuff on the QI show hosted by Stephen Fry. They also have a very funny podcast that you should definitely check out. ↩
Okay, it is a bit more complicated than that but still it’s synchronous.↩