Geting properties getter method with dot notation

I'm having difficulty using Objective-C properties. I am showing a code snippet to explain my doubts:

hijras

@interface A : NSObject
@property (nonatomic,getter = isChosen) BOOL chosen;
@end

main.m

A *myClass = [[A alloc]init];

myClass.chosen = YES;
NSLog(@"1. myClass.chosen = %hhd", myClass.chosen);
myClass.chosen = NO;
NSLog(@"2. myClass.chosen = %hhd", myClass.chosen);          
NSLog(@"3. myClass.chosen = %hhd", [myClass isChosen]);      
NSLog(@"4. myClass.chosen = %hhd", myClass.isChosen);

OUTPUT

1. myClass.chosen = 1
2. myClass.chosen = 0
3. myClass.chosen = 0
4. myClass.chosen = 0

Everything is clear to me, except for the last line of code, where I get the value of the selected property with myClass.isChosen: I understand the point syntax myClass.chosen, because the compiler converts it to message notation syntax [myClass isChosen], but I don’t understand why it works myClass.isChosen, or better, I think again the compiler converts it to message notation, but it seems a little strange to me.

, getter , . , , , NSLog 2 4 .

+4
1


, Objective-C .

Dot :

NSString *firstName = somePerson.firstName;
somePerson.firstName = @"Johnny";

Dot - . , getter setter, :

somePerson.firstName [somePerson firstName] somePerson.firstName = @ "Johnny" [somePerson setFirstName: @ "Johnny" ] , . readonly, , .

, . myClass.chosen [myClass isChosen]. . [myClass chosen] [myClass isChosen]. .

[self setVar:foo] self.var=foo ,   self->var= foo; [self setVar:foo]
  , self.var , , . ,

, .
Dot (.) setter, getter. getter. , . Obj-C 2.0: " , , . " "". , , .

2
. ..

-, isOn, .on .isOn - . (, , ), " ", - . Cocoa , . , . , - , .

" , , , ". -Aaron Hillegass (Cocoa Mac OSX, 3rd Ed)

, ...:)

+4
source

All Articles