Use CoreData For First iPhone App?
Im in the midst of making my first iPhone app. Much of the UI is finished so most of what I have left is database stuff.
It is a simple gym log app and I want users to be able to see their data online. Whether or not it will be editable or read-only via the web portal is determined on how difficult it would be to implement.'
I currently have all exercises stored in a plist that is loaded into a table. I want to have user accounts (registrations) and basic profile views etc. Most data I need to snyc and store will be NSStrings and NSDate and NS int etc, nothing too custom.
Will Cor开发者_高级运维eData fit my needs? And if I use CoreData, can I make my web portal via HTML/CSS and use MySQL or SQLite to sync?
I'm very new to database stuff and I'm going to read Apple's CoreData documentation tonight.
Core Data is great for storing data on your device but looks like you want to sync data to a web service. You should definitely not try and send Core Data objects (i.e. .sqlite files) back and forth. Look into JSON, there are a few libraries available but I have used json-framework by Stig Brautaset and it is a great library.
Turning your data into a JSON string for transmission to a web service is easy as long as you can first put it into an array or a dictionary. Receiving JSON data is even easier since the JSON parser creates objects such as arrays and dictionaries for you which you can then access in the normal way.
XML is another alternative but I don't think it is as easy to work with due to the libraries available not being as great as the JSON libraries.
You should use Core Data for your app because Core Data is not a database system but rather an object graph management system for creating the model layer of a Model-View-Controller design app (and the Apple API pretty much requires that design pattern.)
The model layer is the actual guts of the program. It is where the actual logic central to the utility of the app gets done. Everything else is just an interface to the user, servers or other apps.
For example, in your app, your model layer will model of simulate some kind of real-world objects, events or conditions related to a gym workout e.g. workout times, schedules, reps, exercise series etc. All the logical relationships in between these real-world things will be encoded in the data model and no where else. Core Data makes that simple to implement.
Once the data model is configured, then all you have to do to finish the app is to slap on one or more interfaces. In your case, it sounds like you want an UI on the device, a JSON interface to a server somewhere and possibly an http server within the app itself running over Wifi. If your data model is already completely configured, implementing each interface becomes trivial and, most importantly, changes made in one interface are instantly reflected in all the others.
So, it's good to learn Core Data. In fact it is good to master it. It will let you simply churn out the apps once you become skilled.
However, having said all that, don't let the pursuit of an elegant/perfect design get in the way of shipping. Your code can be inelegant and butt ugly and still succeed if you users never suffer for it. Beautiful code that just sits on the developer's drive benefits no one. Make it work with what you know now and get it out the door. You can always refractor later.
Core Data does have a learning curve precisely because it is so powerful. If you plan on doing a lot of apps you should take the time to learn it but, again, don't let the learning curve get in the way of shipping.
精彩评论