您的位置:首页 > 其它

今天开始进入狂暴状态,开启疯狂面具

2013-03-25 16:04 183 查看
 

1.objective-c中的数字对象都有哪些,简述它们与基本数据类型的区别是什么?

数字对象是 NSNumber

基本数据类型为 fload double char long int .它们都不是对象,不能向它们发送消息,

不能将这些基本数据类型,直接存储到NSArray里面,可以使用NSNumber 类根据这些数据类型来创建对象。

搜索了一下,发现,数字对象,除了我提到的那个以外,还有NSValue,NSNull

对于,NSNumber比较熟悉,NSValue和NSNull我用的比较少。

先说说,NSNull,因为在NSArray和 NSDictionary 中nil有特殊含义(表示列表结束),所以不能在集合中放入nil值,如果确实需要存储一个表示“什么都没有”的值,可以使用NSNull类,只有一个方法

+(NSNull *)null;

例如

[contact setObject:[NSNull null] forey:@"home fax"]

访问如下:

id homefax;

homefax=[contact objectForKey:@"home fax"];

if(homefax=[NSNull null])

{

//..............................

}

 

///////////////////////////////////////////////////////////////////////////

NSNumber 是NSValue 的子类,NSValue 可以包装任何值

...................................此处省略一万字

//    NSMutableArray *mutableArray=[[NSMutableArray alloc] init];

//    CGRect rect=CGRectMake(1, 2, 2, 3);

//    NSValue *rectValue=[NSValue valueWithBytes:&rect objCType:@encode(CGRect)];

//    [mutableArray addObject:rectValue];

//    NSValue *rectValueFromArray=[mutableArray objectAtIndex:0];

//    CGRect rectFromArray;

//    [rectValueFromArray getValue:&rectFromArray];

 CGRect rect=CGRectMake(1, 2, 2, 3);
    NSValue *value=[NSValue valueWithCGRect:rect];
    CGRect rectAfter;
    [value getValue:&rectAfter];

2.nslog 函数输出一个浮点类型,结果四舍五入,保留一位小数。
 

    float f=123.355;
    NSLog(@"%.1f",f);
    //加0.5,取整,呵呵,又忘了这个算法了
    float afterfloat=round(f*10+0.5)/10;
    NSLog(@"%f",afterfloat);

    NSLog(@"%0.20f", 1.345); // output 1.34**
    NSLog(@"%0.2f", 1.345); // output 1.34**
    NSLog(@"%0.20f", 1.3451);// output 1.35
    NSLog(@"%0.2f", 1.3451);// output 1.35
    NSLog(@"%0.2f", round(1.345 * 100)/100.);//output 1.35

不要忘了加0.5,取整    http://www.cocoachina.com/bbs/simple/?t46794.html

里面还有个有意思的现象:http://stackoverflow.com/questions/12122092/why-this-output-nslog0-2f-1-345-output-1-34

  //3
//    NSString *string=@"20|http:";
//    NSRange range=[string rangeOfString:@"|"];
//    NSString *front=[string substringToIndex:range.location];
//    NSString *after=[string substringFromIndex:range.location+1];
//    NSLog(@"front:%@,after:%@",front,after);

 

//4

    //NSDictionary

//    NSMutableDictionary

//    NSMutableDictionary *mutableDictionary=[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"object1",@"key1",@"object2",@"key2", nil];

//    NSLog(@"Before Add:%@",mutableDictionary);

//    [mutableDictionary setObject:@"object3" forKey:@"key3"];

//    NSLog(@"Before Delete:%@",mutableDictionary);

//    [mutableDictionary removeObjectForKey:@"key3"];

//    NSLog(@"After Delete:%@",mutableDictionary);

//    NSLog(@"%@",[mutableDictionary objectForKey:@"key1"]);

5.

////其实

////    NSString *path=[[NSBundle mainBundle] pathForResource:@"" ofType:@""];

//    

//    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);

//    //(lldb) po documentationpath

//    //(NSString *) $4 = 0x0835c370 /Users/CompanyName/Library/Application Support/iPhone Simulator/6.0/Applications/66EBAED0-858D-424B-A78E-896E3B0AFECB/Library/Documentation

//    NSString *documentationpath=[paths objectAtIndex:0];

//

//    NSFileManager *fileManager=[[NSFileManager alloc] init];

//    NSString *destinationPath=[NSString stringWithFormat:@"%@/UserData",documentationpath];

//    if ([fileManager fileExistsAtPath:destinationPath]) {

//        [fileManager createDirectoryAtPath:destinationPath withIntermediateDirectories:false attributes:nil error:nil];

//    }

6.调用self.name的时候,执行的是name属性的set方法,调用name的时候,直接给对象的实例变量赋值。

 
  int a=5;
    int b;
    b=SQUAKE(a++);
    
//    a=7;b=30
    a=5;
    b=SQUAKE(++a);
    //42

7,定义属性时,什么时候用copy,resign,retain?
12.声明一个静态方法和一个实例方法。
13.写一个发送同步http请求,并返回结果的方法
14.怎样启动一个新县城,子线程怎样刷新主UI
15.什么是MVC,你工作时怎样运用它。

2.进程间通信的方式有——
3.链表逆序(链表交叉)
4.c 语言中讲讲static 变量和 static 函数有什么作用

1.static 全局变量 与 普通变量;局部变量 普通变量;static 函数  和普通函数。

#define Per_YEAR (365*24*60*60)UL 后面这个干嘛的
4.写一个委托
5.写一个NSString 类的实现。

8.关键字const 有什么含义?
9.static 关键字的作用 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: