开发者

about get value from sqlite

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜