views:

50

answers:

2

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 giant 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?

+1  A: 

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.

Joshua Nozzi
Ok so I should:- see if I cant fix the issue with the memory leak using my sqlite solution- if I cannot or it becomes to complicated to do so, just add that datamodel and add the code needed to work with Core Data.correct?
kevin Mendoza
Well ... :-) ... I'd inject one step after "if I cannot." Ask SO about the specific issues you're having.
Joshua Nozzi
A: 

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.

Eiko
When I try to add a data model it wants me to add it to a particular class, what class should I add it too?If I do stick with sqlite are there any ways of handling Large object Arrays that minimize memory leakage and usage?
kevin Mendoza
That last half would be one of the things to pose as a separate question on SO. First, no matter the size, there should be no leaks. Second, do you REALLY need a large array, or could you manage with smaller subsets of your data for your given view? Third, if the answer to the second question is "YES" (and of course you've explained why in great detail), then how much of an individual "row" from a SQLite table do you really need to represent on-screen? I'm betting the answer is less than you're currently assuming.
Joshua Nozzi