上一页 1 2 3 4 5 6 7 8 ··· 24 下一页
摘要: 集合类(如:NSArray、NSSet、NSDictionary等)均可获取到NSEnumerator, 该类是一个抽象类,没有用来创建实例的公有接口。NSEnumerator的nextObject方法可以遍历每个集合元素,结束返回nil,通过与while结合使用可遍历集合中所有项。例子中使用了与前例相同的Photo对象,具体定义参考隐式循环这一节。#import <Foundation/Foundation.h>#import "Photo.h"int main (int argc, const char * argv[]){ NSAutoreleasePoo 阅读全文
posted @ 2011-05-11 09:40 chenjunbiao 阅读(3541) 评论(1) 推荐(1) 编辑
摘要: 定义一个Photo类,并带有2个draw方法, 一个带参数、一个不带参数。Photo.h#import <Foundation/Foundation.h>@interface Photo : NSObject {@private }-(void) draw;-(void) draw:(NSNumber*) number;@endPhoto.m#import "Photo.h"@implementation Photo- (id)init{ self = [super init]; if (self) { // Initialization code here. 阅读全文
posted @ 2011-05-10 10:37 chenjunbiao 阅读(894) 评论(0) 推荐(0) 编辑
摘要: 代码:#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; //Objective-C 没有提供相关的函数生成随机数,不过C供了rand(), srand(), random(), srandom(), arc4random()几个函数。 //其中arc4random()不用seed //生成0到100的随机数 int x = arc4random() % 100; 阅读全文
posted @ 2011-05-10 09:58 chenjunbiao 阅读(612) 评论(0) 推荐(0) 编辑
摘要: 1. 服务器端返回json时,日期对象经常是/Date(1304902921487)/ 这种格式。使用如下代码转换成js正常的Date对象。value = new Date(parseInt(value.replace("/Date(", "").replace(")/",""), 10));2. 另一种方式是使用Epoch格式时间,即1970年1月1日到目前的毫秒数。这种处理方式可以进行更好的转换。 阅读全文
posted @ 2011-05-09 17:44 chenjunbiao 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 参考文章:http://blog.codingmylife.com/?p=85#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString *path = @"/Users/billchen/Desktop/f1.rtf"; NSString *temp = @"Hello Friend"; int i = 100; 阅读全文
posted @ 2011-05-09 13:14 chenjunbiao 阅读(2663) 评论(0) 推荐(0) 编辑
摘要: NSNumber可以包装常规的C类型成为一个Objective-C对象,可以存储任何的数字类型,以及BOOL和char。#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSMutableArray *array = [NSMutableArray arrayWithCapacity:3]; [array addObject:[NSNumber numberWit 阅读全文
posted @ 2011-05-06 10:10 chenjunbiao 阅读(2512) 评论(0) 推荐(0) 编辑
摘要: NSMutableSet 集合成员是无序的。对对象进行枚举所得到对象的顺序不能保证相同。向集合中添加相同对象时只会保留一个副本。和其它集合类一样添加移除对象都会分别收到retain和release消息。#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSMutableSet *fruits = [NSMutableSet setWithCapacity:2]; 阅读全文
posted @ 2011-05-06 10:02 chenjunbiao 阅读(723) 评论(0) 推荐(0) 编辑
摘要: NSMutableDictionary 用于处理值对集合。保存到键的对象必须实现了copyWithZone:方法。和NSMutableArray一样添加到容器时对象收到retain消息,把对象从容器中移除时收到release消息,任何想在移除对象还要对该对象进行操作必须先对该对象发出一条retain消息,在使用完成后需要release。#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool all 阅读全文
posted @ 2011-05-06 09:53 chenjunbiao 阅读(3268) 评论(1) 推荐(0) 编辑
摘要: NSMutableArray 只能保存Objective-C对象,没有边界检查,超出边界会抛出运行时异常。添加到Array中的对象会收到一条retain消息,当从数组中删除该对象或者数组本身被release了数组中的对象都会收到一条release消息。#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSMutableArray *mutableFruitBask 阅读全文
posted @ 2011-05-06 09:32 chenjunbiao 阅读(578) 评论(0) 推荐(0) 编辑
摘要: 1. 折分字符串操作:#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; //将一个句子分解为单独的单词 NSString *string1 = @"my name is bill"; NSArray *words = [string1 componentsSeparatedByCharactersInSet:[NSCharacterSet wh 阅读全文
posted @ 2011-05-04 10:12 chenjunbiao 阅读(793) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 24 下一页