標籤: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 錯題