好吧,我有 2 个班级,想将 NSString 从 class2 获取到 class1。
我哪里错了?
类1.h
#import <Cocoa/Cocoa.h>
#import "class2.h"
@class class2;
@interface class1 : NSObject
-(IBAction)getstringfromclass2(id)sender;
@end
类1.m
#import "class1.h"
@implementation class1
-(IBAction)getstringfromclass2(id)sender {
class2 *controller = [[class2 alloc] init];
NSLog(@"%@", [controller getstring]);
}
@end
类2.h
#import <Cocoa/Cocoa.h>
@interface class2 : NSObject {
NSString *astring;
}
-(NSString)getstring;
@property (readwrite,retain) NSString *astring;
@end
类2.m
#import "class2.h"
@synthesize astring;
@implementation class2
-(NSString)getstring {
return [self astring];
}
@end