On Aug 24, 2016, at 4:25 PM, Jens Alfke <j...@mooseyard.com> wrote: > >> On Aug 24, 2016, at 1:04 PM, Andreas Falkenhahn <andr...@falkenhahn.com> >> wrote: >> >> Now, will "setFormatter" call retain on "formatter" or not? Looking >> at "retainCount" seems to suggest so, although I know that this >> isn't reliable and shouldn't be done at all... > > These days, with ARC, we call those “strong references” vs. “weak” or > “unretained” references.
It used to be that when someone mentioned looking at retainCount there would a flurry of admonitions not to do that. This thread doesn't feel complete without such an admonition, so I'll refer you to this. :) <https://developer.apple.com/reference/objectivec/1418956-nsobject/1571952-retaincount> > Do not use this method. > Strong (retained) references are the default for properties. There are a few > cases in system frameworks where a property is weak or unretained — usually > this is used for delegates or data sources, to avoid reference cycles that > can lead to memory leaks. In this case the docs should call out the style of > the reference. If there’s no mention of it, you can assume it’s strong. Yup. That said, there's at least four ways to find out how a property is declared -- bearing in mind what others have said about how you should focus on what *you* do with the formatter object, not so much what the NSTextField object does. 1. The docs show the Objective-C declarations of properties and methods. What might happen is: - You'd look at the docs for NSTextField. - You wouldn't see the formatter property in those docs. - You'd check the docs for its superclass, NSControl. - You'd see this: @property(strong) __kindof NSFormatter *formatter 2. Alternatively, you might be looking at this line of code... [textField setFormatter:formatter]; ...and you might Option-click on the "setFormatter" and see popup help showing the same Objective-C declaration. 3. You might do a *plain* click on "setFormatter" and hit Option-Command-2 to show the Quick Help inspector, which again shows the same declaration. I'm a big fan of Quick Help. 4. If you don't trust the docs and only trust code, you might Command-click on "setFormatter", which will open NSControl.h and select the declaration of the property. On the machine I'm using now, I get the following, which I see has the additional "nullable" keyword: @property (nullable, strong) __kindof NSFormatter *formatter; --Andy (a few days behind on my email) _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com