iphone(3)-------iphone需要了解的基础框架

Foundation框架

Foundation框架实现很多的数据储存和其他类似的基础类。Foundation框架包括Value,collection类,有数字,数列,集合,字典等。Notifications,对象可以发出其他对象可能像知道的它们正在做什么事情的通告,并且不需要这两个对象互相有指针,一个对象可以注册已知的另外一个对象将会发送的特定通告。

Undomanager框架提供了基本的撤销支持

NSObject

根类(基本类)

实现许多基本功能

内存管理

introspection

对象的对等性

NSString

它是基于unicode的字符串,所有幕后存储的数据都是unicode的,因此它可以处理世界上所有的语言。

利用已经存在的字符串而修改为新字符串的方法:

-(NSString*)stringByAppendingString:(NSString*)existString;//串联字符串

-(NSString*)stringByAppendingFormat(NSString*)existString;

-(NSString*)stringByDeletingPathComponent;//如果你有磁盘上的某文件的路径,你可以发 //送小给它,新的字符串会带上一个相同的路径与上次的值的串接。

常用的NSString方法

-(BOOL)isEqualToString:(NSString*)string;

-(BOOL)hasPrefix:(NSString*)string;//是否把string当作前缀

-(int)intValue;//从字符串中取回数字值,如果是字符串中带有多个值,它会取回第一个数值

-(double)doubleValue;//如果没有值,则会取回0

字符串常量

NSString* aString=@”hello world”;

它们永远不会解除分配,它们是常量字符串,因此实际上它们是在你的可执行文件的数据部分。

因此你没有理由需要把它们解除分配。它们就在磁盘上。


NSMutableString

NSString的子类,用NSMutableString定义的字符串可以被修改

常用的NSMutableString方法

+(idstring;

-(void)appendString:(NSString*)string;

-(void)appendFormat:(NSString*)format....;

例子:

NSMutableString*newString=[NSMutableString string]

[newStringappendString:@”hi”];

[newStringappendFormat:@”,my favorite number is :%d”,[self favoriteNumber]];


Collections

Array数列是有序的对象,或说是有序的对象集合

Dictionary字典是键值对

Set集合是无序的唯一对象的集合

NSArray

常用的NSArray方法

+arrayWithObject:(id)firstObj,.....;//nil结尾

-(unsigned)count;//数组中的元素个数

-(id)objectAtIndex:(unsigned)index;//数组中特定索引的对象

-(unsigned)indexOfObject:(id)object;//数组中特定对象的索引,如果不存在则返回NSNotFound常量。你不会取回nil值,你只能得到NSNotFound

NSInteger不是一个对象,只是一个c语言的整数,NSNumber是一个对象。

当你调用[NSNullnull],这实际上是一个特殊类型的对象,它代表null,你可以把它放在你的数列中,但是你不能放nil到你的数列中。如果你调用带着容量的数列,然后添加对象,你仍然需要nil结尾。

NSMutableArray

NSArray的子类,可变数列

常用的一些NSMutableArray方法

+(NSMutableArray*)array;

-(void)addObject:(id)object;

-(void)removeObject:(id)subject;

-(void)removeAllObjects;

-(void)insertObject:(id)objectatIndex:(unsigned)index;

例子:

NSMutableArray* array=[NSMutableArray array];

[arrayaddObject:@”red”];

[arrayaddObject:@”Green”];

[arrayremoveObjectAtIndex:1];


NSDictionary

常用的NSDictionary方法

+dictionaryWithObjectAndKeys:(id)firstObject,....;//nil结尾,传递时,第一个值是对象,第二个对象是第一个对象的值,键值的排列下去

-(unsigned)count;

-(id)objectForKey:(id)key;//如果没有找到返回的是nil

NSMutableDictionary

NSDictionary的子类

常用的NSMutableDictionary方法

+(NSMutableDictionary*)dictionary;

-(void)setObject:(id)objectforKey:(id)key;

-(void)removeObjectForKey:(id)key;

-(void)removeAllObjects;

例子:

NSMutableDictionarycolors=[NSMutableDictionarydictionary];

[colorssetObject:@”orange” forKey:@”HighlightColor”];

NSSet

无序的对象集合,对象唯一

常见的NSSet方法

+setWithObject:(id)firstObject,....;//nil结尾

-(unsigned)count;

-(BOOL)containsObject:(id)object;


NSMutableSet

NSSet的子类,可变集合

常用的NSMutableSet方法

+(NSMutableSet*)set;

-(void)addObject:(id)object;

-(void)removeObject:(id)object;

-(void)removeAllObjects;

-(void)insertsectSet:(NSSet*)otherSet;

-(void)minusSet:(NSSet*)otherSet;


Enumeration

列举集合中的元素,经常用于NSArray,NSDictionary,NSSet等。

例子:

NSArray* array=.....;

//以前的做法

Person*person;

intcount=[array count];

for(inti=0;i<count;i++)

{

person=[arrayAtIndex:i];

NSLog([persondescription]);

}

//新的做法


for(Person*person in array)

{

NSLog([persondescription]);

}


NSNumber

NSNumber是一个对象,用于封装c中的数值型,是NSValue的子类,没有的可变的数值与之对应。

常用的NSNumber方法

+(NSNumber*)numberWithInt:(int )value;

+(NSNumber*)numberWithDouble:(double)value;

-(int)intValue;

-(double)doubleValue;


其他的类

NSData/NSMutableData代表任意字节

NSDate/NSCalendarDate日期/日历日期


获得对象

利用factory方法

NSString's +stringWithFormat;

NSArray's +array;

NSDictionary's+dictionary

上面的几种方法会返回autoreleased对象,因此它们会进入你的资源池,不需要担心内存管理.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值