Ok, really embarassed to announce that I got the problem all wrong. It seems like the object has been out of scope in the first place. the myObject is actually [myObjectList objectForIndex:index] where myObjectList is NSMutableArray *myObjectList. This is not a synthesized property. Object is a class derived from NSObject ( @interface Object : NSObject)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for(Object* p in myObjectList)
{
NSLog(@"%@", p.name); //this returns a garbled message
}
MyObjectDetailViewController * vc = [[MyObjectDetailViewController alloc] initWithStyle:UITableViewStylePlain];
vc.object = [myObjectList objectAtIndex:indexPath.row];
[self.navigationController pushViewController:vc animated:YES]; //when i hover over "vc" in debugger, it shows that vc.object is defined(i see my name variables) but when i hover over myObjectList in the previous line, the objects say "out of scope"
[vc autorelease];
}
To cover all ground, here is where the array is instantiated. This function is a callback function from sqlite's sqlite3_exec.
int callback (void* context, int count, char** values, char** columns)
{
NSMutableArray *list = (NSMutableArray*)context;
Object *obj = [[Object alloc] initWithName:[NSString stringWithUTF8String:values[kName]]];
[list addObject:obj];
[obj release];
NSLog(@"After release");
for(Object *p in list)
{
NSLog(@"%@", p.name); //this prints out okay
}
return SQLITE_OK;
}
I hope this makes the problem a little clearer. The fact that myObjectList is out of scope but I seem to be able to retrieve its objects is really weird...