I am compiling a list of results from a SQLite3 database in a UITableView . The code in which I am extracting text from the database looks like this:
char *menuNameChars = (char *) sqlite3_column_text(statement, 1); NSString *menuName = [[NSString alloc] initWithUTF8String:menuNameChars]; NSLog(@"Retrieved %s,%@ from DB.", menuNameChars, menuName);
When I use initWithUTF8String , sometimes the information is copied properly from the database. Sometimes, however, information is displayed correctly from char* , but not from NSString :
2011-10-24 22:26:54.325 [23974:207] Retrieved Cravin Chicken Sandwich β Crispy, (null) from DB. 2011-10-24 22:26:54.327 [23974:207] Retrieved Cravin Chicken Sandwich β Roast, (null) from DB. 2011-10-24 22:26:54.331 [23974:207] Retrieved Jr Chicken Sandwich, Jr Chicken Sandwich from DB. 2011-10-24 22:26:54.337 [23974:207] Retrieved Prime-Cut Chicken Tenders - 3 Piece, Prime-Cut Chicken Tenders - 3 Piece from DB.
Now, if I replace initWithUTF8String with initWithCString , the code works fine. However, Xcode 4.2 tells me that initWithCString deprecated. I know enough to understand that I do not want to use legacy code, but if initWithUTF8String does not work, what should I use?
source share