What I Learned Today
Fixing FMDB crashes on iPhone

I was trying to use the FMDB wrapper for sqlite in a simple iphone app, but I found that I would get a crash whenever I created a DB in one function and then use it again in a later one. I eventually realized that the memory region that was supposed to be holding my DB was being freed up without me knowing it.  To fix the problem, I edited the FMDatabase.m file as follows:


+ (id)databaseWithPath:(NSString*)aPath {
//return [[[self alloc] initWithPath:aPath] autorelease]; REMOVE CALL TO AUTORELEASE
return [[self alloc] initWithPath:aPath];
}

For some reason the library sets the database object to be autorelease’d, a concept that I don’t fully understand in objective C.  In any case, removing the autorelease flag makes the program work correctly.  This may be adding a slight memory leak, but since I only create one database object ever, I don’t think it really matters for my purposes…

Trouble adding CoreData library to existing iPhone app

I was trying to get core data to work inside an app that I had already started, but I was getting errors like:

/…/Classes/MyAppAppDelegate.h:12: error: expected specifier-qualifier-list before ‘NSManagedObjectModel’

It seemed like it was not including the CoreData library, but I had added the framework—what else did I need to do?

It turns out, that you also have to edit the MyApp_Prefix.pch file to add the line:

#import <CoreData/CoreData.h>

Now it works!