"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]