views:

370

answers:

1

Here is the interface of my object:

@interface MyItem : NSObject {
 sqlite3 *database;
 NSInteger *primaryKey;
 NSInteger *accountKey;
 NSInteger *categoryKey;
 NSString *title;
 BOOL hydrated;
 BOOL dirty;
 NSData *data; // Why do I need this?
}

The primary key will be auto generated in Sqlite and I am storing the integers, foreign keys of account and category in the MyItem table.

The account and category will have a meaningful description. Should I add properties for the descriptions as well? Like so:

NSString *accountDesc;
NSString *categoryDesc;

So that in my Hydrate method I can do a join to category and account.

What is the best practice to do this?

My goal is on the initial launch of the App, I will display a Tableview with title and category descriptions.

+4  A: 

Why not use Core data? You will get the best practice then - plus it is fast and it gives loads of other benefits.

Core data would create objects for you with exposed properties - and handle relationships - and lazily load the objects to make memory management much eaiser. You code becomes much easier to read too.

Grouchal
I am new at Obj-C, how do you use core data and how is it related to my issue? To solve my problem, how do I do it using core data? I am using the Sqlite Books example as a guide.
Picflight
Core Data is a standard interface for accessing sqlite - it has only been introduced in OS 3.0 and really is much easier to use than the mixture of ObjC and C in the sqlbooks example.You should find example code called Locations in the documentation and there is plenty of other documentation on the Core Data functions.Core Data is a library that has come from OS X and is widely used on the mac. You design your data model visually and it would then generate your classes for you. You asked about best practice and Core Data is now best practice.
Grouchal
Wow! Thanks for pointing out core data! I have been reviewing the documentations and it looks similar to ADO.NET Entity Data Model which I have used in C#.
Picflight
Of course, it predates ADO.NET Entity Framework and several of Microsoft's other efforts in that area by quite a while. :)
Chris Hanson