Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone, sqlite3, how do detect a null date, getting error when assigning to a NSString?

This is my code

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

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

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSPlaceholderString initWithUTF8String:]: NULL cString'

like image 601
Jules Avatar asked Jun 14 '26 12:06

Jules


1 Answers

You cannot initialize NSString objects with a NULL pointer so just check for that condition:

const char* date = (const char*)sqlite3_column_text(statement, 3);
NSString *enddate = date == NULL ? nil : [[NSString alloc] initWithUTF8String:date];
like image 149
Nikolai Ruhe Avatar answered Jun 16 '26 09:06

Nikolai Ruhe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!