How to use features such as viewDidLoad
or appDidBecomeActive
in Xcode 4.6.1 for OSX 10.8, which are available only for OSX 10.10 and above. Please suggest the alternative ways to use these functions.
Asked
Active
Viewed 495 times
3

cacau
- 3,606
- 3
- 21
- 42

user2715756
- 31
- 7
-
I don't expect you can do this. You have quite an outdated version of Xcode. – Almo May 11 '15 at 18:25
-
Rather than implementing an override of `-viewDidLoad`, just override `-loadView`. Call through to `super` and then put any additional code after that. That's effectively "view-did-load" code. As to `appDidBecomeActive`, that doesn't seem to be part of any Cocoa API. Where did you find that? – Ken Thomases May 11 '15 at 19:56
-
You can only use what is available through the supported SDK. – Volker May 11 '15 at 20:46
-
When you say `appDidBecomeActive`, do you mean `applicationDidBecomeActive:`? That has been part of OS X since 10.0. – JWWalker May 11 '15 at 22:04
-
@JWWalker : ya thats what i mean applicationDidBecomeActive is what am talking about .... – user2715756 May 12 '15 at 05:21
2 Answers
3
To expand on Ken Thomas's comment; this is the code that I use:
- (void)loadView
{
[super loadView];
// if we're running on 10.8 or older…
if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_8) {
[self viewDidLoad]; // call viewDidLoad (added in 10.9)
}
}
//
// This will be called by loadView pre-10.9; directly otherwise
//
- (void)viewDidLoad {
// --- YOUR CODE HERE ---
} // viewDidLoad

geowar
- 4,397
- 1
- 28
- 24
-
Thanks for the tip. Is there any reason to call `[super viewDidLoad];` from a derived class? – ATV Jul 17 '15 at 16:45
-
It would depend on if the super class implements a viewDidLoad method. To be paranoid, you could use instancesRespondToSelector on the superclass to determine if it's implemented there. Note: sending respondsToSelector: to super is equivalent to sending it to self. Instead, you must invoke the NSObject class method instancesRespondToSelector: You cannot simply use [[self superclass] instancesRespondToSelector:@selector(aMethod)] since this may cause the method to fail if it is invoked by a subclass. – geowar Jul 17 '15 at 17:14
-
Shouldn't this be `NSAppKitVersionNumber <= NSAppKitVersionNumber10_9` as the header indicates `viewDidLoad` wasn't added until 10.10. – spinacher Apr 28 '16 at 22:38
-
Alternatively the explicit version check could be replaced by `if (![NSViewController instancesRespondToSelector:@selector(viewDidLoad)])…`. – spinacher Apr 28 '16 at 22:52
0
I'd override setView
@interface MyViewController : NSViewController
@end
@implementation MyViewController
- (void)setView:(NSView*)v {
super.view = v;
// if we're running on 10.8 or older…
if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_8) {
[self viewDidLoad]; // call viewDidLoad (added in 10.9)
}
}
@end

Daij-Djan
- 49,552
- 17
- 113
- 135