On 12/03/15 10:55, Jonathan Schleifer wrote: > As John explained, instancetype takes care of it. However, in a > pre-instancetype world, it still works because your assumption is wrong: > >> In order to determine whether the initWithContentsOfFile returns an >> NSDictionary* or an NSArray* > > Both actually have an initWithContentsOfFile that returns id (or now > instancetype).
I don't have 10.10 handy, but in that version Apple reportedly changed those method signatures to literally return resp. NSDictionary* and NSArray* rather than id/instancetype as before. It's also shown like that now in the documentation: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/#//apple_ref/occ/instm/NSDictionary/initWithContentsOfFile: and https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/#//apple_ref/occ/instm/NSArray/initWithContentsOfFile: > This means they both have the same signature and there's no need for the > compiler to know whether it's an NSDictionary or an NSArray. You explicitly > tell the compiler the type when you assign it to a variable of that type, but > before that, it's only an id for the compiler and it doesn't care. Even with the different return types it doesn't matter for the message dispatch (the selector is the same, as also indirectly pointed out by Uli), but it does matter for static type checking at compile time. To provide some more context: I'm asking this to determine how I should deal with this in the Free Pascal Compiler for our Objective-Pascal dialect. Thanks for all the replies till now. Jonas _______________________________________________ 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]
