type NSApp as NSApplication* instead of id

Originator:kenferry
Number:rdar://19087143 Date Originated:
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:
 
NSApp is typed as id. This causes problems, such as confusing Don Melton:

    It seems I’ve forgotten how to Objective-C. I’m getting the loopiest compiler warning for the following code:

    [NSApp setDelegate:self];

(from https://twitter.com/donmelton/status/537730312017412097)

The problem is that 
(1) the different versions of setDelegate: all now take different types, because AppKit has adopted formal protocols for delegates instead of typing everything as id
(2) the compiler guessed wrong, grabbed one of the other setDelegate: methods for typing.

This would be less confusing if NSApp was typed as NSApplication.

Unfortunately it would still have a downside – if an app subclasses NSApplication as FooApplication, methods of FooApplication will not be able to be sent to NSApp without casting. This still seems less confusing to me.

(Ideally the compiler would let you say "this is an id qualified to NSApplication subclasses", so that sending any method of any subclass of NSApplication did not warn.)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!