开发者

iPhone - Synthesize and ivar use from outside the class?

开发者 https://www.devze.com 2023-02-19 11:43 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消