开发者

Why should I use Core Data for my iPhone app?

开发者 https://www.devze.com 2022-12-13 15:07 出处:网络
I\'m working on my 2nd iPhone app and am curious about Core Data. Time on the project is limited, as is my time overall.

I'm working on my 2nd iPhone app and am curious about Core Data. Time on the project is limited, as is my time overall.

I'm the only dev and I have a feeling that Core Data would be useful but I can't clearly explain why.

Please excuse the following obfuscation .. the app needs to retrieve a list of f开发者_如何学Pythonoos from a central server. Users can then add a bar, from a list of bars, to the foos, then add a baz from a list of bazes(!?) to the bar, then add some optional photo and description to the baz.

Once the user is happy with their bar and baz work they then hit a sync button to upload their data back to the central server.

As you can see, it's a simple data driven drill down app, but I'm still not sure I can justify using Core Data with our time constraints - the learning curve looks steep.

If argue to my boss that we should be using Core Data, what bullet points can I shoot at him? Logic grenades are also appreciated.


Core Data will mainly help in the auxiliary facets of the application - things like data persistence, presentation, etc. Some bullet points for your boss:

  • Core Data manages save and undo functionality for you. It has a persistent store, which tracks changes, and can be flushed to the disk automatically at any number of times (app close, etc.).
  • Core Data and related classes provide easy ways to get your entities into UITableViews, like NSFetchedResultsController.
  • Core Data abstracts away a lot of the messy things you'd otherwise have to deal with yourself, such as lists of objects, one-to-many or many-to-many relationships, or constraints on object attributes, into a single nice clean object-oriented interface.
  • Core Data comes with a nice graphical object model editor that can help you think through your object/entity design, and refine it as you go. (It also supports migration, so if you decide later that you want different attributes on your entities, you can do that relatively easily.)

Sure, the learning curve may be a bit steep, but the Apple examples are great to start with, and the Core Data documentation is very complete and helpful. Once you've got Core Data down, it'll be a breeze to build your app.


To leverage CoreData, you'll need to know a fair amount of Cocoa technologies, concepts, and patterns. The learning curve is not really steep if you know these things. If it looks steep, I would avoid making it critical to your project, and then just learn during downtime, finally using it once you are comfortable with it. It is definitely not a beginner technology; you'll need a good programming foundation, including Cocoa specific technologies and concepts. A lot of people see it and think it will be easy for them, because they would, could get a lot for free. It's like a code generator, pretty close to useless to somebody who uses it to do just that (churn out code), rather than using it skillfully in response to the problem set.


As far as the learning curve goes, I don't think it's as bad as you think. Using Apple's example classes and default CoreData project template, I was able to have a working CoreData app (fairly simple, but not trivial) up in a single afternoon, and it only took a couple days of playing around with the code before I had a really good understanding of what all the moving parts were (all while developing the rest of the app, so no time was wasted in tinkering).

CoreData works very...logically, I guess, and it's incredibly convenient. It saves you a lot of overhead, and I know it certainly saved me a lot of time writing that app. The short initial investment in learning the new technology was well worth it in the long run, now that I have such a powerful tool in my holster.


I'm still in the X-Code 101 range of knowledge, but the first app I undertook on my own used core data (after reading a good tutorial).

There is a lot of boilerplate software that comes already written in the empty app template, but the actual programmer interaction with the data base functionality is minimal and straightforward.

Give it a shot: it's easier than you think.


A Core Data managed object can have all its data saved to database and is only referenced as an ID in memory. Thus Core Data can save lots of memory especially when you have lots of model data. Once you use Core Data you don't even need to worry about model data memory problems anymore.


You have a couple of different options for a persistent local store, but you would need to use one of them anyway so why not use Core Data?

As for learning curve, there are applications in the examples that will help you here. It's pretty straightforward once you walk through the samples.

-t


The other answers here do a good job of explaining why you might use core data, but as its learning curve seems to be a common concern, it might be useful for those who stumble upon this question to know that there is an alternative with a considerably "less steep" learning curve: Realm.

Here is a brief Quora post on why you might consider Realm over Core Data: https://www.quora.com/Why-would-you-use-Realm-over-Core-Data

0

精彩评论

暂无评论...
验证码 换一张
取 消