views:

226

answers:

2

I am fairly new at object oriented programming (but am starting to pick up fairly quickly), and am working on an application for the iphone. I need to make a multidimensional array, (10,000 or more rows, 8 collums) ordered as such:3 collums should contain boolean values, one should contain an integer, two need to hold GPS coordinates (usually have a decimal, like 62.422342), one needs to hold a 30 character string. is there an easy way to create such an array, and if so, to define the array elements prior to user interation?

A: 

You might want to make each row an object, and keep an NSArray of those objects. Each "column" would be a property on the object. This would be a good choice if each row actually does represent an object.

Otherwise you could have an NSArray of NSArrays to represent the 2D array. Not a perfect solution, because it's possible to have rows/columns of different lengths, but it would do.

You could always roll your own, and make a kind of "Table" class that acts as a 2D NSArray and enforces correct row/column length.

Tom Dalling
A: 

You should maybe have a look at Core Data and store your data in a database. I'm currently reading Beginning iPhone 3 Development and it's got a chapter about Core Data. It doesn't go into very much detail, but is a good introduction and should be enough to get started.

Thomas Müller
are there any online resources for Core Data? I have a book on programming with Cocoa, perhaps that can assist as well?
Cocoa Programming for Mac OS X (http://www.bignerdranch.com/products.shtml) covers some Core Data and there are a few tutorials out there, for instance http://cocoadevcentral.com/articles/000085.php. There's also some stuff directly from Apple: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html or http://developer.apple.com/iphone/library/documentation/DataManagement/Conceptual/iPhoneCoreData01/Introduction/Introduction.html and probably more Have a look on Google.
Thomas Müller
Another thing I wanted to mention: Core Data is only available in iPhone OS 3 and up, so if you need to support older versions you can't use Core Data.
Thomas Müller
Thanks, there were some helpful hints in your links and im finally starting to create my database, albeit slowly..