[OC 5th Day]

Source: Internet
Author: User

"Mastering" 03-point syntax Introduction and use

#import<Foundation/Foundation.h>#import "Person.h"intMainintargcConst Char*argv[]) {@autoreleasepool { person*p = [PersonNew]; //calling the Set method//[P setage:18];//[P setname:@ "Zhang San Fung"]; //dot Syntax: Xcode features, Xcode helps us with code substitution//object. Property name//Note that this time (p.age) is not directly accessing the instance variable,//instead, when Xcode sees the dot syntax (p.age), it automatically replaces//p.age--replace-->[p setage:18]P.age = -; //p.name = @ "Chicken sister"; //        ////int a = [P age]; Call the Get method////NSString *s = [p name];//        //        //Note that the p.age here appears on the right side of the equals sign//        //In fact, when Xcode sees P.age appearing on the right side of the equals sign,//        //It will help us replace the p.age---with---> [P age];//int a = P.age; //call the Get method//nsstring *s = p.name;//        //        //emphasis: Whether P.age is replaced with a Get method or a set method is generally dependent on//        //P.age appears on the left or right side of the equal sign (whether it is a set value or a value)////        //NSLog (@ "\nage:%d,name:%@", a,s);NSLog (@"%d", P.age); }    return 0;}

Self.age  dead Loop
The essence is the invocation of the method, no method, no point method

"Master" [email protected] keywords introduction and use

use  of @property 1 , using format:        @property data type method name (remove set)// is the method name is not a property name, so the  underscore nothing  2,     function: 1, in Xcode4. Before 4 , used to help us implementthe get/set method    declaration 2, in Xcode4.  4

"Mastering" [email protected] keyword introduction and use

Person.h

#import <Foundation/Foundation.h>@interface  person:nsobject{    // instance variable    NSString *_name;     int _age;} // @property compiler directives, the compiler helps us to _age _name Get/set method declaration int  *name; -(void) test; @end

Person.m

#import "Person.h"@implementation Person//@synthesize help us implement the get and set methods of instance variables@synthesizeAge//Help us create a variable age//@synthesize weight;/*-(void) Setage: (int) age{self->age = age; }-(int) age {return age;}*/@synthesizename;/*-(void) SetName: (NSString *) name{self->name = name;}-(NSString *) name{return name; } */-(void) test{NSLog (@"\n_age =%d,_name =%@", _age,_name); NSLog (@"\nage =%d,name =%@", Age,name);}@end

"Mastering" [email protected] enhanced use

[OC 5th Day]

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.