IOS: Parsing of different attributes declaration methods

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.