开发者

about get value from sqlite

开发者 https://www.devze.com 2022-12-11 07:02 出处:网络
Code Sample: NSString *str= [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectS开发者_开发百科tatement, 1)];

Code Sample:

NSString *str= [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectS开发者_开发百科tatement, 1)];
Test *t=[[Test alloc] init];
t.str=[str copy]; // why use "copy" here?
[str release];


It looks to be bad coding, for two reasons. Since str is being discarded, you might as well assign it, rather than a copy, to t.str. Second, and more importantly, setters should take care of retaining or copying data.


Should be:

NSString *str= [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 1)];
Test *t=[[Test alloc] init];
t.str=str; // No point copying to release original.
0

精彩评论

暂无评论...
验证码 换一张
取 消