码迷,mamicode.com
首页 > 其他好文 > 详细

objective-c 错题

时间:2014-11-27 21:50:22      阅读:208      评论:0      收藏:0      [点我收藏+]

标签: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 错题

标签:io   ar   使用   sp   for   on   2014   log   bs   

原文地址:http://www.cnblogs.com/iOS-mt/p/4127194.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!