OC语法简写
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OC语法简写相关的知识,希望对你有一定的参考价值。
NSNumber
[NSNumber numberWithInt:666] 等价于 @666
[NSNumber numberWithLongLong:666ll] 等价于 @666ll
[NSNumber numberWithUnsignedLong:666ul] 等价于 @666ul
[NSNumber numberWithFloat:66.6f] 等价于 @66.6f
[NSNumber numberWithDouble:66.6] 等价于 @66.6
[NSNumber numberWithBool:YES] 等价于 @YES
[NSNumber numberWithChar:‘A’] 等价于 @‘A’
NSArray
[NSArray array] 等价于 @[]
[NSArray arrayWithObject:a] 等价于 @[a]
[NSArray arrayWithObjects:a, b, c, nil] 等价于 @[a,b,c]
[arr objectAtIndex:i] 等价于 arr[i];
[arr replaceObjectAtIndex:i withObject:newObj]
等价于 arr[i] = newObj
NSMutableArray * mutableArr = [@[a,b,c] mutableCopy];
NSDictionary
[NSDictionary dictionary] 等价于 @{}
[NSDictionary dictionaryWithObject:obj1 forKey:key1]
等价于 @{key1:obj1}
[NSDictionary dictionaryWithObjectsAndKeys:obj1, key1, obj2, key2, obj3, key3, nil]
等价于 @{key1:obj1,key2:obj2,key3:obj3}
[dic objectForKey:key] 等价于 dic[key]
[dic setObject:obj forKey:key] 等价于 dic[key] = obj
NSMutableDictionary * mutableDic = [@{key1:obj1} mutableCopy];
以上是关于OC语法简写的主要内容,如果未能解决你的问题,请参考以下文章