well, I have 2 classes and want to get NSString from class2 to class1.
where do I wrong?
class1.h
#import <Cocoa/Cocoa.h>
#import "class2.h"
@class class2;
@interface class1 : NSObject
-(IBAction)getstringfromclass2(id)sender;
@end
class1.m
#import "class1.h"
@implementation class1
-(IBAction)getstringfromclass2(id)sender {
class2 *controller = [[class2 alloc] init];
NSLog(@"%@", [controller getstring]);
}
@end
class2.h
#import <Cocoa/Cocoa.h>
@interface class2 : NSObject {
NSString *astring;
}
-(NSString)getstring;
@property (readwrite,retain) NSString *astring;
@end
class2.m
#import "class2.h"
@synthesize astring;
@implementation class2
-(NSString)getstring {
return [self astring];
}
@end
check your some expression. NSString -> NSString *
#import <Cocoa/Cocoa.h>
@interface class2 : NSObject {
NSString *astring;
}
-(NSString *)getstring;
@property (readwrite,retain) NSString *astring;
@end
class2.m
#import "class2.h"
@synthesize astring;
@implementation class2
-(NSString *)getstring {
return [self astring];
}
@end
You need to return a pointer to NSString
:
-(NSString*)getstring {
return [self astring];
}
And:
-(NSString*)getstring;