3
votes

I am getting that error when I try to do this using ARC with the following SQLite code:

NSMutableArray *rows = [[NSMutableArray alloc] init];
sqlite3_exec(database, "select distinct category from billy", callback, rows, NULL);

Anyone know how to fix this?

1
Could you provide the code for your callback function, as well? That might influence the answer here. - Brad Larson

1 Answers

6
votes

Be warned that I never do ARC, but casting rows parameter to (__bridge_retained void *) should help if I understand the document correctly.

Here is the code I use for testing.

static int myCallback(void* ptr, int i, char** p1, char** p2) {
    NSMutableArray* array = (__bridge_transfer NSMutableArray*)ptr;
    return 0;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSMutableArray *rows = [[NSTestMutableArray alloc] init];
    sqlite3_exec(NULL, "select distinct category from billy", &myCallback, (__bridge_retained CFMutableArrayRef)rows, NULL);
}

(__bridge_transfer ) is for transferring the ownership back so ARC will release it correctly. I override dealloc of my NSTestMutableArray to show that it is really deallocated, and it won't be deallocated if I comment the __bridge_transfer line.