iOS Programmers: Don't Use Core Data over iCloudSeptember 27, 2012, at 09:17:34 AM
A few people have e-mailed me and friends have asked when they will get an iPad version of Songsmith. My standard response has been, "I'm going to roll out iCloud support and universal app at the same time".
Songsmith was written as a SQLite app so the first change in my 2.0 branch was to change the back end to Core Data and write the code to move any existing user data from SQLite to Core Data. This part went well and I did enough testing to feel confident that my code was sound. Next up, iCloud support. This is where things started to break down.
Turning off iCloud on a device for a short amount of time and turning it back on created havoc. Data was just lost. Devices would completely stop syncing. An article on Drew McCormack's website best described what was happening. It was also my first red flag.
I did something I hate doing; I started scouring the Apple Developer forums (The Mos Eisley of developer forums). Things did not look rosy. There were a lot of questions but very few answers. I was on the verge of scrapping iCloud completely. I decided to ask reddit. I listed four points of contention:
Core Data over iCloud works fine in an optimal situation but things like turning iCloud off and on, a device that stops syncing for a while, uninstalling and reinstalling the app, having the user delete app data can all really muck things up and cause data loss or errors while syncing. There does not seem to be a great solution for some of these issues
Its nearly impossible to foresee and plan for everything a user might do that could corrupt his/her database or break future syncs. At some point data loss is likely for at least a very small percentage of users
iCloud takes a lot of time to code and especially test. That time could be better spent adding other features to the app or making new apps (I'm not as concerned about this, I've just seen it come up multiple times)
- Finally: Core Data over iCloud is just not ready for production yet and should be avoided
The responses were unanimous: Yup. Don't use it.
Hope is not lost, though. Document sharing over iCloud seems to be pretty stable. No transaction logs that only get sent once, no needing to wipe out local copies of files. Ray Wenderlich has written an awesome tutorial on setting it up. I am currently testing a new solution that stores data in XML plist files that use UIDocument to sync to the cloud. My test app is running great, although the performance hit of using text files is noticeable. I'm creating a small API to make using plist files over iCloud a breeze. I'll stick it on github when its good enough for an alpha release.
Also, iOS 6 is supposedly much better with Core Data over iCloud. I cannot speak to this as I did all of my testing on 5.1. As someone pointed out in the reddit thread, its a moot point because we have to support iOS 5 in the foreseeable future.
tl;dr: Don't use Core Data over iCloud. Use UIDocument over iCloud or offer your own client/server solution for multi-device data sharing.