課程
/移動(dòng)開發(fā)
/iOS
/iOS基礎(chǔ)入門之Foundation框架初體驗(yàn)
? ? ?為什么輸出數(shù)組中有數(shù)組類型的元素時(shí),輸出這個(gè)元素是它的地址而不是具體的值呢?為什么直接用%@輸出是具體的值,而在數(shù)組中輸出卻是地址?
2015-12-03
源自:iOS基礎(chǔ)入門之Foundation框架初體驗(yàn) 3-3
正在回答
#import <Foundation/Foundation.h>
#import "PeopleAll.h"
int main(int argc, const char * argv[]) {
? ? @autoreleasepool {
? ? ? ? PeopleAll *people1 = [[PeopleAll alloc] init];
? ? ? ? PeopleAll *people2 = [[PeopleAll alloc] init];
? ? ? ? PeopleAll *people3 = [[PeopleAll alloc] init];
? ? ? ? NSLog(@"people1 = %p",people1);
? ? ? ? NSLog(@"people2 = %p",people2);
? ? ? ? NSLog(@"people3 = %p",people3);
? ? ? ? people1.peopleName = @"張三";
? ? ? ? people2.peopleName = @"李四";
? ? ? ? people3.peopleName = @"王五";
? ? ? ? NSLog(@"姓名:%@",people1.peopleName);
? ? ? ? NSLog(@"姓名:%@",people2.peopleName);
? ? ? ? NSLog(@"姓名:%@",people3.peopleName);
? ? ? ??
? ? }
? ? return 0;
}
2015-12-05 19:58:55.130 people[637:20956] people1 = 0x100200790
2015-12-05 19:58:55.131 people[637:20956] people2 = 0x1002055d0
2015-12-05 19:58:55.132 people[637:20956] people3 = 0x100200210
2015-12-05 19:58:55.132 people[637:20956] 姓名:張三
2015-12-05 19:58:55.132 people[637:20956] 姓名:李四
2015-12-05 19:58:55.132 people[637:20956] 姓名:王五
Program ended with exit code: 0
因?yàn)閿?shù)組里保存的元素是對(duì)象,%@輸出的也是地址,你后面那個(gè)問(wèn)題代碼發(fā)上來(lái)看看
舉報(bào)
學(xué)會(huì)Foundation框架,能滿足你所需要的大部分東西
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-12-05
#import <Foundation/Foundation.h>
#import "PeopleAll.h"
int main(int argc, const char * argv[]) {
? ? @autoreleasepool {
? ? ? ? PeopleAll *people1 = [[PeopleAll alloc] init];
? ? ? ? PeopleAll *people2 = [[PeopleAll alloc] init];
? ? ? ? PeopleAll *people3 = [[PeopleAll alloc] init];
? ? ? ? NSLog(@"people1 = %p",people1);
? ? ? ? NSLog(@"people2 = %p",people2);
? ? ? ? NSLog(@"people3 = %p",people3);
? ? ? ? people1.peopleName = @"張三";
? ? ? ? people2.peopleName = @"李四";
? ? ? ? people3.peopleName = @"王五";
? ? ? ? NSLog(@"姓名:%@",people1.peopleName);
? ? ? ? NSLog(@"姓名:%@",people2.peopleName);
? ? ? ? NSLog(@"姓名:%@",people3.peopleName);
? ? ? ??
? ? ? ??
? ? }
? ? return 0;
}
2015-12-05 19:58:55.130 people[637:20956] people1 = 0x100200790
2015-12-05 19:58:55.131 people[637:20956] people2 = 0x1002055d0
2015-12-05 19:58:55.132 people[637:20956] people3 = 0x100200210
2015-12-05 19:58:55.132 people[637:20956] 姓名:張三
2015-12-05 19:58:55.132 people[637:20956] 姓名:李四
2015-12-05 19:58:55.132 people[637:20956] 姓名:王五
Program ended with exit code: 0
2015-12-04
因?yàn)閿?shù)組里保存的元素是對(duì)象,%@輸出的也是地址,你后面那個(gè)問(wèn)題代碼發(fā)上來(lái)看看