views:

53

answers:

1

Hello everyone

As I know, NSApplicationDelegate is available in SDK for 10.6

Is there any similar protocol as NSApplicationDelegate for ealier version(mine is 10.5.8)?

Thank interdev

+1  A: 

Functionally, yes. But formally, no.

The point is, protocols before Objective-C 2.0 didn't have the concept of optional methods. Therefore, something called informal protocol was used instead. Basically, the header files just added a category to NSObject as in

@interface NSObject (NSApplicationDelegate)
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
....
@end

This way, the compiler won't warn you when you call a delegate method on an arbitrary object. Now it's formalized as a formal protocol:

@protocol NSApplicationDelegate
@optional
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
....
@end

When you implement an application delegate, the difference would be in 10.5 and before you would have

@interface YourAppDelegate:NSObject {
...
}
@end

while you would have in 10.6 and later

@interface YourAppDelegate:NSObject<NSApplicationDelegate> {
...
}
@end

So, as you find in the documentation for NSApplicationDelegate, the protocol is formalized in 10.6 but not before. However, the functionality has been there since 10.0.

The Cocoa world changes quite quickly, and the documentation tends to describe only the latest version, so I would recommend you to upgrade to 10.6 if it's possible. That will save you tons of hours of hair-scratching, especially if you're a beginner.

Yuji