문제

I've read many things about the @synthesize call. About its use, ...
So I have made a test, and its result gives me a strange feeling. Let me explain...

Lets write in an object .h

@interface AnObject : NSObject {
    NSString* aaTest;
}

@property(nonatomic, retain) NSString* bbTest;

-(void)log;

Then in its .m

@synthesize bbTest = aaTest;

-(void)log {
    NSLog(@"Inside var : %@", aaTest);
    NSLog(@"Inside property : %@", self.bbTest);
}

In another .m, let's write :

#import "AnObject.h"

then into one method :

    AnObject* testCtrl = [[AnObject alloc] init];
    testCtrl.bbTest = @"Some string";
    NSLog(@"Outside property : %@", testCtrl.bbTest);
    [testCtrl log];

We are ok that here, including only the .h, the synthesize call is not known from the other object. Looking at the Log, it gives :

Outside property : Some string
Inside var : Some string
Inside property : Some string

So... Isn't that strange ?

도움이 되었습니까?

해결책

In your synthesize call, you assign bbtest to aaTest (note the capital T). That's not the same as aatest

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top