开发者

Objective-C / UIButton / SetTitle

Does the setTitle method of UIButton retain the NSString passed as argument ?

I guess I can rely on the fact that the property is defined as:

property(nonatomic,readonly,retain) UILabel *titl开发者_开发百科eLabel

In this case, I think that it does retain the string.

Thanks, Apple92


You can count on framework classes to retain things that they need unless otherwise documented. This is part of Cocoa's memory management rules. You should read that document and let it sink in, because once you understand it, basically all of your memory management questions go away — conversely, if you don't take the time to understand that document, you'll always feel uncertain. Luckily, it's pretty simple.

Also, I would be careful about relying too much on other people telling you the rules. Especially in informal settings like Stack Overflow, people have a tendency to simplify and misspeak, leading to misunderstandings — meanwhile, the official rules have been proofread many, many times over the years.


Yes - you've pretty much answered your own question there.

Not all API's retain as the original NSString may change in some way - one API may receive an NSString reference, but it's actually an NSMutableString, for exapmle.

The Google coding standards for Objective C has a section about this, here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜