Code:
/*description of the property declaration:-----------------------1@interface ... {ID name} @end the declared property can actually be considered a private property, because it is only referenced in the method by name, and cannot be referenced externally by "object.name" (internal also cannot be referenced by self)--------------- -------2@interface. @property ID name@end The declared property can be considered a public property, referenced internally by "Self.name", and externally through the "Object.name" reference------------ -----------3@implementation. @synthesize Name@end allows properties to be declared in the property, in addition to the self reference in the internal method, can also be directly referenced with the property name---------------- -------4self.name is actually two methods (Setter,getter): id value = [self name][self setName = ...]----------------------- 5 Summary: If the framework relies on a property that is @property, it cannot be implemented as private, or the program can be blown off*/#import<Foundation/Foundation.h>@interfacestudent:nsobject{NSString*name;} @property NSString*address;-(void) toString;@end@implementationStudent@synthesizeaddress;-(Student *) init{name=@"Lishujun"; Self.address=@"Beijing"; returnSelf ;}-(void) tostring{NSLog (@"%@ %@", name, [self address]);}@endintMainintargcConst Char*argv[]) {@autoreleasepool {//Insert code here ...Student *student =[[Student alloc]init]; [Student toString]; [Student setaddress:@"Tongzhou"]; [Student toString]; NSLog (@"%@", student.address); //syntax error, no SetName this method//[Student setname:@ "Shujunli"]; //[student toString]; } return 0;}
IOS: Parsing of different attributes declaration methods