IPhone, sqlite3, how to determine the zero date, get an error when assigning NSString?

This is my code.

NSString *enddate = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 3)]; 

I need to have null dates, but when null is passed to this string, I get an error

* Application termination due to an uncaught exception 'NSInvalidArgumentException', reason: '* - [NSPlaceholderString initWithUTF8String:]: NULL cString'

+3
source share
1 answer

You cannot initialize NSString objects with a NULL pointer, so just check this condition:

 const char* date = (const char*)sqlite3_column_text(statement, 3); NSString *enddate = date == NULL ? nil : [[NSString alloc] initWithUTF8String:date]; 
+13
source

All Articles