1.字符串
*NSString
创建字符串:
NSString *str = @"Hello,world";
NSString *height = [NSString stringWithFormat:@"Your height is %d feet,%d inches",5,11];
实例方法:
字符串长度:
-( NSUInteger)length;
字符串比较:
-(bool)isEqualToString:(NSString *)aString;
-(NSComparisonResult)compare:(NSString *)string;
-(NSComparisonResult)compare:(NSString *)string options:
(NSStringCompareOptions)mask;
2.集合大家族
* NSArray、NSMutableArray
* NSEnumerator
* NSDictionary、NSMutableDictionary
创建字典:
* NSArray、NSMutableArray
* NSEnumerator
* NSDictionary、NSMutableDictionary
1. + (id) dictionaryWithObjectsAndKeys: (id) firstObject, ...;
2. @{key:value,...};
访问字典中的对象:
1. - (id) objectForKey: (id) aKey;
2. dict[key];
添加可变字典:
+(id)dictionaryWithCapycity:(NSUInter) numItems;
添加元素:
-(void)setObject:(id)anObject forKey:(id)aKey;
删除元素:
-(void)removeObjectForKey:(id) aKey;
3.其他数值对象
*NSNumber
装箱:
创建NSNumber对象(将基本数据类型封装成NSNumber对象)
1.
+ (NSNumber *) numberWithChar: (char) value;
+ (NSNumber *) numberWithBool: (BOOL) value;
+ (NSNumber *) numberWithInt: (int) value;
+ (NSNumber *) numberWithFloat: (float) value;
2.
NSNumber *number;
number = @'X'; //字符型
number = @12345; //整型
number = @12345ul; //⽆无符号整型
number = @123.45f; //浮点型
开箱:
从NSNumber对象中取出基本数据类型
- (char) charValue;
- (int) intValue;
- (float) floatValue;
- (BOOL) boolValue;
- (NSString *) stringValue;
创建NSValue对象,即装箱
+ (NSValue *) valueWithBytes: (const void *)value objType:(const char *)type;
提取NSValue中的数值,即开箱
- (void)getValue:(void *)buffer;
Cocoa提供的将常用struct型数据与NSValue互相转换的便捷方法
+ (NSValue *)valueWithPoint:(NSPoint)aPoint;
+ (NSValue *)valueWithSize:(NSSize)size;
+ (NSValue *)valueWithRect:(NSRect)rect;
- (NSPoint)pointValue;
- (NSSize)sizeValue;
- (NSRect)rectValue;
创建NSNull对象
+ (NSNull *) null;