On Mar 14, 2015, at 05:21 , Jonathan Schleifer <[email protected]>
wrote:
>
> The documentation is kind of wrong here. I'm guessing instancetype is
> replaced by the class (which is basically what is done by the compiler) and
> then it's not shown anymore that it's instancetype.
The documentation isn’t wrong. It reflects what’s in the 10.10 SDK headers —
initWithContentsOfFile: and initWithContentsOfURL: are return-typed NSArray* or
NSMutableArray*, while all the others are return-typed instancetype.
I don’t know why, but after puzzling over it for a while I realized there is
significant difference that might be the reason. To see it, consider possible
NSArray subclasses.
So, the result of
[[MyArraySubclass alloc] initWithObject: x]
is a MyArraySubclass. However, the result of
[[MyArraySubclass alloc] initWithContentsOfURL: u]
is only a NSArray. (“is a” means “isKindOf” in both cases, not “isMemberOf”)
My guess is that the Cocoa initWithContentsOf… methods actually return a
different object from the one that was allocated**, and the returned object is
of some fixed subclass of NSArray rather than of the class of the allocation.
If that’s true, declaring those methods to return instancetype would be wrong.
** Of course, in general all of the collection class cluster initializers
return a different object from the one that was allocated, since they have a
custom alloc that returns a placeholder. But normally an object of the original
class is created as the replacement for the placeholder.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/objc-language/archive%40mail-archive.com
This email sent to [email protected]