objective-c 錯題

來源:互聯網
上載者:User

標籤:io   ar   使用   sp   for   on   2014   log   bs   

 

    //1,

    NSString *name = [[NSString alloc]initWithString:@"張三"];

    NSLog(@"%d",[name retainCount]);

    //2014-11-27 20:43:20.290 OC考試錯題[1750:303] -1

    

    //2,

    NSString* testObject = [[NSData alloc] init];

    //編譯時間,NSString類型,運行時,NSData類型

    

    //3,

    NSArray *(^aBlock)(NSString * str,NSString *str2);

    //聲明一個傳回值為NSArray,並且帶兩個字串對象的BLOCK類型變數

    

    //4,

    NSMutableDictionary * dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"2",@"3",@"3",@"4", nil];

    NSArray *arr = [[NSArray alloc] initWithArray:[dic allKeys]];

    NSString *str = [[NSString alloc] initWithFormat:[arr objectAtIndex:0],[arr objectAtIndex:1],[arr objectAtIndex:2]];

    NSLog(@"%@",str);

    //2014-11-27 20:47:22.678 OC考試錯題[1761:303] 2

    

    //5,

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSString *sstr = [NSString stringWithFormat:@"abc"];

    NSString *str2 = [sstr retain];

    [pool release];

    NSLog(@"sstr retainCount = %ld,str2 retainCount = %ld",[sstr retainCount],[str2 retainCount]);

    // sstr retainCount = 1,str2 retainCount = 1

    

    

    //6,

    NSMutableDictionary * dic1 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"1",@"3",@"1",@"4", nil];

    NSArray *arr1 = [[NSArray alloc] initWithArray:[dic1 allKeys]];

    NSArray *arr2 = [[NSArray alloc] initWithArray:[dic1 allValues]];

    NSMutableDictionary *dic2 = [[NSMutableDictionary alloc] initWithObjects:arr1 forKeys:arr2];

    NSLog(@"%@",dic2);

    //  1 = 4;

    

    //7,將@”2B青年”替換成@”文藝青年”

    NSRange range1 = {0,2};

    [@"2B青年" stringByReplacingCharactersInRange:range1 withString:@"文藝"];

    

    //8,

    NSMutableDictionary * dic3 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"2",@"3",@"3",@"4", nil];

    [dic3 setObject:@"1" forKey:@"3"];

    [dic3 removeObjectForKey:@"1"];

    NSLog(@"%@",dic3);

    //  2 = 1;3 = 1;4 = 3;

    

    //9,在類方法中bu可以使用執行個體變數。

    

    //10,執行個體對象都是通過調用類方法產生的。

    

    

    

    

    

    return 0;

objective-c 錯題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.