-
聲明方法查看全部
-
對象方法和類方法的區(qū)別注意點查看全部
-
新版本IOS SDK,可以不用在h文件聲明成員變量,直接在m文件使用即可。如果在h文件聲明了屬性,則在m文件會自動生成成員變量。查看全部
-
NSString * _peopleName; int _peopleAge; int _peopleSex; 類內(nèi)使用成員變量,類外使用屬性查看全部
-
people.h -(id)init; //id可能會導(dǎo)致類型錯誤 -(instancetype)init; //重寫初始化方法 -(instancetype)initWithPeopleName:(NSString *) peopleName andPeopleAge:(int)peopleAge;//自定義初始化 people.m -(instancetype)initWithPeopleName:(NSString *) peopleName andPeopleAge:(int)peopleAge{ self=[super init]; if(self){ _peopleName=peopleName; _peopleAge=peopleAge; } return self; } main.h People *p2=[[People alloc] initWithPeopleName:@"張三" andPeopleAge:20]查看全部
-
People.h -(int)showWIthA:(int)a; -(int)showWithA:(int)a andB:(int)b; //方法帶參 :代表有參數(shù) int 參數(shù)類型 a參數(shù)名 People.m -(int)showWIthA:(int)a { return a; } -(int)showWithA:(int)a andB:(int)b { return a+b; } main int a1=[p1 showWithA:10]; NSLog(@"a1=%d",a1); int a2=[p1 showWIthA:10 andB: 20]; NSLog(@"a2=%d",a2);查看全部
-
People.h 申明方法 -(void)report; // - + 方法的類型 - 對象方法:用對象名調(diào)用 + 類方法 +(void)report1; People.m 方法實現(xiàn) -(void)report { NSLog(@"-號:report"); [People report1]; //使-號方法可以調(diào)用+號方法 _peopleName = @"123"; //可隨意調(diào)用成員變量 } static NSString *_peopleName1; +(void)report1 { NSLog(@"+號:report1"); [[people alloc] report]; //+號方法調(diào)用-號方法 先實例化一個 _peopleName1=@"123"; //只能調(diào)用靜態(tài)變量 } main 調(diào)用方法 [p1 report]; // - [people report1]; // +查看全部
-
@synthesize peopleName=_peopleName //在People.m中講屬性名和成員變量名進(jìn)行對應(yīng) - (instancetype) init { self=[super init]; if (self){ // ...... } return self; } main.m NSLog(@"peopleName - %@",[p1 getName]); //輸出查看全部
-
{ //@public 只可用指向調(diào)用p1->_peopleName NSString *_peopleName; int _peopleAge; int _peopleSex; //People類的成員變量 只可在類內(nèi)使用 people.m _peopleName=@"張三"; } @property(nonatomic,strong)NSString *peopleName; //變成屬性查看全部
-
command+n 創(chuàng)建類 繼承nsobject 在.m中引入 #import "People.h" // 實例化對象 People *p1=[[People alloc] init]; [類名 方發(fā)名] [對象名 方法名] People *p2=[People new]; 不推薦 打印 NSLog(@"p1-%p",p1); 打印三個內(nèi)存地址查看全部
-
Oc查看全部
-
ok wo查看全部
-
創(chuàng)建類,得到對象。類到對象,對象化,實例化;對象到類,抽象化。查看全部
-
OOA OOP查看全部
-
還沒查看全部
舉報
0/150
提交
取消