摘要:
转:http://tangqiaoboy.blog.163.com/blog/static/1161142582011873458953/主道路,人行道,不要占用资源,在单机的多线程程序里,为了保证UI的操作线程安全,都会要求UI的操作在一个特定的线程里面进行,通常情况下,这个特定线程指的是程序的主线程。所以,当你的代码在主线程运行的时候,实际上会造成UI不能重绘,应该尽量把长时间的操作放到非主线程中去。 对于在iphone里的app也一样应该遵守上面这个原则。不过iphone的 UIWebView的stringByEvaluatingJavaScriptFromString只能在主线程里面被 阅读全文
摘要:
-(void)doInitialWork{ mStream = [[XMPPStreamalloc]init]; dispatch_queue_t im_queue; im_queue = dispatch_queue_create("im.queue", Nil); [mStreamaddDelegate:selfdelegateQueue:im_queue]; dispatch_block_t b = ^{ TTLog(@"aa"); };同步,不同步,是任务安装添加的顺序执行而已,还是顺序执行的,同步的话,第一个执行完了,第二个才执行,而不同步的话 阅读全文
摘要:
转:http://www.cnblogs.com/qingche/p/3496190.html(清澈Saup)1.iOS的三种多线程技术 1.NSThread每个NSThread对象对应一个线程,量级较轻(真正的多线程)2.以下两点是苹果专门开发的“并发”技术,使得程序员可以不再去关心线程的具体使用问题ØNSOperation/NSOperationQueue面向对象的线程技术ØGCD —— Grand Central Dispatch(派发) 是基于C语言的框架,可以充分利用多核,是苹果推荐使用的多线程技术哦,原来有三种 线程 技术啊,哦,原来是这样,以... 阅读全文
摘要:
Example 3. A content message with receipt requested My lord, dispatch; read o'er these articles. Note: A sender MUST include an 'id' attribute on every content message that requests a receipt, so that the sender can properly track ack messages. 阅读全文
摘要:
1,声明 创建一个队列dispatch_queue_tnetwork_queue; network_queue=dispatch_queue_create("com.myapp.network",nill); 2,异步并行 执行(队列 + 要执行的代码)dispatch_async(network_queue, ^{ UIImage *cellImage = [self loadMyImageFromNetwork:image_url]; // 将图片cache到本地 [self cacheImage:cellImage]; ..... } );3,执行完,... 阅读全文
摘要:
转自anxonli:http://anxonli.iteye.com/blog/1097777这次的文章集中与iOS的多核编程和内存管理,为什么?因为iPad 2已经是双核CPU了!虽然iPad 1的应用已经不慢了,但大家完全可以使用苹果的多核编程框架来写出更加responsive的应用。多核运算在iOS中concurrency编程的框架就是GCD(Grand Central Dispatch), GCD的使用非常简单。它把任务分派到不同的queue队列来处理。开发者把任务代码装到一个个block里面,操作系统把这些任务代码分派到不同的资源里去处理,一个简单的例子来说,为什么初学者写table 阅读全文
摘要:
/*** Just like the sendElement: method above,* but allows you to receive a receipt that can later be used to verify the element has been sent.** If you later want to check to see if the element has been sent:** if ([receipt wait:0]) {* // Element has been sent* }** If you later want to wait until t. 阅读全文
摘要:
肺都切除了,还让怎样呼吸,//下线- (void)goOffline{ XMPPPresence *presence = [XMPPPresencepresenceWithType:@"unavailable"]; [mStream sendElement:presence];// [mStream removeDelegate:self];[mStreamdisconnect];} 阅读全文
摘要:
select *from instantMessage where ownerId = 1 orderby sendDate asclimit 10 offset 0 阅读全文
摘要:
-(NSArray *)sortArrayByComparator:(NSArray *)arr{ return [arr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { ChatMessageInfo *info1 = obj1; ChatMessageInfo *info2 = obj2; if (info1.sendDate > info2.sendDate) { returnNSOrderedDescending; }else if(info1.sendDate < ... 阅读全文