I'm pulling a listing of results from a SQLite3 database into a UITableView
. The code where I pull text from the database is like so:
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 though, the information is displayed properly from the char*
, but not from the 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 perfectly. However, XCode 4.2 tells me that initWithCString
has been deprecated. I know enough to understand I don't want to use deprecated code, but if initWithUTF8String
isn't working, what should I use?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…