'add property to NSApplication/NSResponder causes error on macOS app

I am trying to migrate one iOS app to macOS, the code below work!

AppDelegate.h

#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
}
@property (nonatomic, assign) NSInteger myProperty;
@end

RootController.h

#import <UIKit/UIKit.h>
 
@interface RootController : UIViewController{}
@property (strong,nonatomic) AppDelegate *appDelegate;
@end

RootController.m

appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.myProperty=5;

so I set the similar code on macOS app

AppDelegate.h

#import <AppKit/AppKit.h>
#import <CoreData/CoreData.h>
#import <Cocoa/Cocoa.h>

@interface AppDelegate :NSResponder <NSApplicationDelegate>{
 
}
@property (nonatomic, assign) NSInteger myProperty;
@end

AppDelegate.m

#import "AppDelegate.h"
 
@implementation  AppDelegate

@synthesize  myProperty;
@end

AppController.h

#import "AppDelegate.h"

@interface AppController : NSWindowController <>{

     
}
@property (strong,nonatomic) AppDelegate *appDelegate;
@end

AppController.m

//..

appDelegate =(AppDelegate *)[[NSApplication sharedApplication] delegate];
appDelegate.myProperty=5;//

cause error

[AppController setMyProperty:]: unrecognized selector sent to instance 0x7f8992b4a280

your comment welcome



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source