I have a memory management problem I can't get my head around on iOS. I'm getting data from a SQLite db where some cells can be empty. So to handle this case, I assign [NSNull null] to my recipient if empty, or the value if not:
NSString *email = (const char *) sqlite3_column_text(statement, 6) == NULL ? [NSNull null] : [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 6)];
But then if I do that:
[email release];
the analyser doesn't like it and I think it crashes my program when the object is actually [NSNull null].
So I've tried:
(id) email == [NSNull null] ? nil:[email release];
But it doesn't work (still crashes and analyser doesn't like it). Any ideas?
Thanks in adv开发者_Python百科ance
I'm using in that case nil
value. For example:
NSString *email = (const char *) sqlite3_column_text(statement, 6) == NULL ? nil : [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 6)];
In such case you can safely call [email release]; // email can be NSString or nil
and all will work as you need.
精彩评论