iPhone stringWithCString 已弃用
我使用此代码从 sqlite 数据库读取数据:
keyFromSql = [NSString stringWithCString:(char *)sqlite3_column_text(preparedStatement, 1)];
但编译器给了我标题中写的警告...那么,从 sqlite 检索值的正确且未弃用的方法是什么?
谢谢!
I use this code to read data from sqlite database:
keyFromSql = [NSString stringWithCString:(char *)sqlite3_column_text(preparedStatement, 1)];
but the compiler give me the warning wrote in the title... so, what is the right and not deprecated method to retrieve a value from sqlite?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你通常会使用 NSUTF8StringEncoding,所以你的代码看起来像
或者你可以使用
I think you'll typically use NSUTF8StringEncoding, so your code would look like
Alternatively you can use
由于 SQLite 始终返回 UTF-8* 编码的字符串, 您可以只使用
+stringWithUTF8String:
。(* 或 UTF-16,如果您使用
sqlite3_column_text16
)Since SQLite always return UTF-8* encoded strings, you could just use
+stringWithUTF8String:
.(* or UTF-16, if you use
sqlite3_column_text16
)[[NSString alloc] initWithBytes:字节长度:计数编码:NSUTF8StringEncoding]
优于
stringWithCString:encoding:
Apple 的Document 的推荐不太好,因为原始方法“不会在 NULL 字符处短暂停止”。
[[NSString alloc] initWithBytes:bytes length:count encoding:NSUTF8StringEncoding]
is preferred to
stringWithCString:encoding:
Apple's Document's recommendation is not very OK, because the original method "doesn’t stop short at a NULL character."