Hikariri / CrossClass

0 stars 0 forks source link

Fix : A get B.arrays #1

Open benjenq opened 7 years ago

benjenq commented 7 years ago
//AppDelegate.h
#import <Cocoa/Cocoa.h>
@class BClass;
@interface AppDelegate : NSObject <NSApplicationDelegate>{

}

@property (assign) IBOutlet NSWindow *window;

@property (nonatomic, strong) BClass *BCLS;

@end

//AppDelegate.m
#import "AppDelegate.h"
#import "BClass.h"
@interface AppDelegate ()

//@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate
@synthesize BCLS = _BCLS;

@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    if (!_BCLS) {
        _BCLS = [[BClass alloc] init];
    }
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

@end

//  AClass.h
#import <Foundation/Foundation.h>

@interface AClass : NSObject

@end

//  AClass.m
#import "AClass.h"
#import "BClass.h"

@implementation AClass

BClass  *BCLS;

-(void)awakeFromNib{
}
- (IBAction)A_Action:(id)sender {
    AppDelegate *app = [NSApplication sharedApplication].delegate;
    BCLS    =    (BClass *)app.BCLS;
    NSLog(@"A_Action:Arr = %@",BCLS.MUarray);
}

@end

//  BClass.h
#import "AppDelegate.h"
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>

@interface BClass : NSObject{
    NSMutableArray  *MUarray;
}
@property NSMutableArray    *MUarray;

@end

//  BClass.m
#import "BClass.h"

@implementation BClass

@synthesize MUarray;

AppDelegate         *AppDeleGet ;
int                 SetUP       ;

-(void)awakeFromNib{

    AppDeleGet   = (AppDelegate *)[NSApplication sharedApplication].delegate;

    MUarray      =  [[NSMutableArray alloc]init];
    SetUP        =  0 ;
//    NSButton    *ButtonSetClass =   [[NSButton   alloc]initWithFrame:CGRectMake(10, 500, 200, 30) ];
//    [ButtonSetClass setTitle:@"Push"];
//    ButtonSetClass.target=self;
//    ButtonSetClass.action=@selector(buttonClick);
//    [AppDeleGet.window.contentView addSubview:ButtonSetClass];
}

-(void)buttonClick{
}

- (IBAction)B_Action:(id)sender {
    NSDictionary *datap = @{[NSString stringWithFormat:@"%d",SetUP]:  @"Test",};
    SetUP++;
    [MUarray addObject:datap];
    AppDelegate *app = [NSApplication sharedApplication].delegate;
    app.BCLS.MUarray = MUarray;
    NSLog(@"MUarray =   %@",app.BCLS.MUarray);
}

-(NSMutableArray *)ReturnArray:(NSMutableArray *)Arr{
    return MUarray;
}

-(void)dealloc{
    SetUP--;
}
@end
Hikariri commented 7 years ago

Really thanks for help! I 'll check the code and debug with suggest,and I think I should be re-learning the objective-c again....