开发者

How easy would It be to adapt Core Data to my app?

开发者 https://www.devze.com 2023-01-11 03:00 出处:网络
I\'m a novice iphone developer, and just completed my first iphone app. After provisioning my iphone for development, I noticed that the app used way too much memory, and that several memory leaks th

I'm a novice iphone developer, and just completed my first iphone app. After provisioning my iphone for development, I noticed that the app used way too much memory, and that several memory leaks that were issuing from the app accessing the sqlite database in the app caused the app to crash often. After running instruments, I have decided that CORE DATA sounds like a better way to go: of course I still need to use the sqlite database that I have.

so my question is this: how easy would it be to adapt an already existing app to run on core data? My app basically shows 17,000 different mapView annotations in small amounts by county, though my database is very simple, just one gia开发者_如何学Pythonnt spreadsheet basically.

in the App delegate, my app opens the Sqlite database, puts some of the data into a locations object with four attributes, and then makes an array of those objects. the first view controller lets the user decide which county ( one of twelve or so) the user wishes to view, and then the last view controller uses a loop to add the selected locations to a mapView.

How should I modify my app in the previous paragraph so that it uses CoreData? Can you point me to any resources that I can use to achieve this (preferably not the Dev Center's CoreData tutorial; overly confusing and more complicated than i need right now)? or do I have to make an entirely new project in xcode and start from scratch?


Apologies for the indirect pontification, but ...

First, I'd say your assertion, "After running instruments, I have decided that CORE DATA sounds like a better way to go..." is flawed. Finding bugs and performance issues in your app doesn't automatically mean a different approach is better - it may only mean you need to fix your memory leaks and/or adjust your approach based on what your profiling shows.

The fact you say you still need to use an existing SQLite database doesn't automatically preclude using Core Data, but it does make your end solution significantly more complicated. If you can possibly get away with using either Core Data or SQLite entirely, that would by far be your best bet.

Also, Core Data is not a beginner (or, I'd argue, even an intermediate) Cocoa technology. It requires significant prerequisite knowledge to do anything more than very basic stuff without becoming hopelessly lost when the inevitable problem arrises. If you're too pressed to take the time to read the documentation and research the technology for now, you're probably better off just fixing the problems with your existing solution.

... and there's nothing wrong with your existing solution (using SQLite directly) at its most basic. The better question(s) to ask is (are) about the specific problems you're having with your current approach.

That said, if you want to adapt an existing iOS-based solution to use Core Data, you'll likely have an easier time of it than if you were targeting Mac OS. Create a basic Core-Data-Based iPhone app project and look at the code. The code to build the Core Data stack is in plain sight. The only other thing to remember is to add an xcdatamodel file like the one found in the empty project. If you've gotten far enough to interface with the SQLite library, you should have enough experience to see clearly how Core Data is used in a standard iOS app.


The steps you need to go to convert to Core Data: - Develop data model (maybe graphically in xcode) - Adopt your code to use core data instead, i.e. rewrite that module - Read your old data and put it into core data

If you have it already running with sqllite, I'd stick with it. If it uses much too many memory, it's probably a bug on your part, or bad partitioning of the data you load into memory, and you want to address this one way or the other - although Core Data makes it maybe a bit easier to get it right.

0

精彩评论

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