nsoperation

PDFKit background search

你。 提交于 2020-06-12 15:53:04
问题 I'm trying to run a search on a background thread using new iOS PDFKit framework. override func main() { if isCancelled { return } pdfDocument = PDFDocument.init(url: book.document.url)! pdfDocument.delegate = self pdfDocument.beginFindString("test", withOptions: [.caseInsensitive, .diacriticInsensitive]) (async) //pdfDocument.findString("test", withOptions: [.caseInsensitive, .diacriticInsensitive]) (sync) } The problem is that none of the PDFDocumentDelegate's methods isn't called and if I

PDFKit background search

喜你入骨 提交于 2020-06-12 15:52:08
问题 I'm trying to run a search on a background thread using new iOS PDFKit framework. override func main() { if isCancelled { return } pdfDocument = PDFDocument.init(url: book.document.url)! pdfDocument.delegate = self pdfDocument.beginFindString("test", withOptions: [.caseInsensitive, .diacriticInsensitive]) (async) //pdfDocument.findString("test", withOptions: [.caseInsensitive, .diacriticInsensitive]) (sync) } The problem is that none of the PDFDocumentDelegate's methods isn't called and if I

多线程&NSObject&NSThread&NSOperation&GCD

心已入冬 提交于 2020-05-05 12:13:15
1、NSThread 每个NSThread对象对应一个线程,量级较轻(真正的多线程) 以下两点是苹果专门开发的“并发”技术,使得程序员可以不再去关心线程的具体使用问题 2、NSOperation/NSOperationQueue 面向对象的线程技术 3、GCD —— Grand Central Dispatch(派发) 是基于C语言的框架,可以充分利用多核,是苹果推荐使用的多线程技术 以上这三种编程方式从上到下,抽象度层次是从低到高的,抽象度越高的使用越简单,也是Apple最推荐使用的。但是就目前而言,iOS的开发者,需要了解三种多线程技术的基本使用过程。因为很多框架技术分别使用了不同多线程技术。 NSThread: 优点:NSThread 比其他两个轻量级,使用简单 缺点:需要自己管理线程的生命周期、线程同步、加锁、睡眠以及唤醒等。线程同步对数据的加锁会有一定的系统开销 NSOperation: 不需要关心线程管理,数据同步的事情,可以把精力放在自己需要执行的操作上 NSOperation是面向对象的 GCD: Grand Central Dispatch是由苹果开发的一个多核编程的解决方案。iOS4.0+才能使用,是替代NSThread, NSOperation的高效和强大的技术 GCD是基于C语言的 NSObject的多线程方法——后台线程 (void

NSOperation - Forcing an operation to wait others dynamically

回眸只為那壹抹淺笑 提交于 2020-01-19 19:02:18
问题 I am trying to implement an operation queue and I have the following scenario: NSOperation A NSOperation B NSOperation C NSOperation D NSOperationQueue queue I start adding A to queue . During the execution of A I need to get some data from B and I can't continue with A until B returns what I need. The same situation will occur for B depending on C and for C depending on D . To manage this, at each NSOperation I have this code: NSOperation *operation; //This can be A, B, C, D or any other

iPhone: Downloading data asynchronously with NSURL request as opposed to [NSData datawithContents ofURL]

梦想的初衷 提交于 2020-01-14 04:31:06
问题 Hi Im a newbie and Im trying to download geocoding data from googleapi webpage. I did it using this: code: NSMutableString *urlStr = [[NSMutableString alloc] initWithString:temp]; NSMutableString *address = [[NSMutableString alloc] initWithString:l.Address]; [address appendString:@" "]; [address appendString:l.CityName]; [address appendString:@" "]; [address appendString:l.State]; [address appendString:@" "]; [address appendString:l.PostalCode]; NSArray *addressArray = [address

iOS之[多线程:NSOperation]

你离开我真会死。 提交于 2020-01-07 06:16:06
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1. NSOperation :fa-exclamation-triangle: 以下是你需要考虑使用 NSOperation 的一些理由: 1.当你需要取消线程任务时,GCD 无法提供取消任务的操作。而 NSOperation 提供了取消任务的操作; 2.当你需要更细的粒度地观察任务改变了状态时,由于 NSOperation 是一个对象,比较 GCD 使用的 block 而言,通过对 NSOperation 对象进行键值观察(KVO)能很容易观察到任务的状态改变; 3.当你需要重用线程任务时,NSOperation 作为一个普通的 Objective-C 对象,可以存储任何信息。对象就是为重用而设计的,这时,NSOperation 比 GCD 使用的 block 要更方便。 1.1 NSOperation简介 实际开发中使用的是NSOperation的两个子类 - NSInvocationOperation - NSBlockOperation :使用block形式组织代码,相对方便 1.2 线程的创建执行过程 异步:创建NSOperation -> 创建NSOperationQueue队列 -> 将NSOperation添加到Queue中 同步:创建NSOperation -> 调用start方法 1.3

Objective-C 后台线程 和 NSOperationQueue

旧街凉风 提交于 2020-01-07 04:28:59
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 后台线程 简单操作,无需创建线程时,可以使用一下函数(以UILabel 为例): [myLabel performSelector:@selector(setText:) withObject:@"hello" afterDelay:0.1f]; 代替平时的操作:[myLabel setText:@"hello"]; 1)创建线程:执行线程函数,将函数要执行的任务从主界面线程中分离出来 [NSThread detachNewThreadSelector:@selector(listenForRequests) toTarget:self withObject:nil ]; -(void)listenForRequests { @autoreleasepool { //doSomething ........ } } 注意:线程函数内创建的任何对象在函数执行完成以后不会得到协防,为防止内存泄漏,在线程函数中需使用@autoreleasepool{}进行内存管理 。 RunLoop 说到 NSThread 就不能不说起与之关系相当紧密的 NSRunLoop。Run loop 相当于 win32 里面的消息循环机制,它可以让你根据事件/消息(鼠标消息,键盘消息,计时器消息等)来调度线程是忙碌还是闲置。

How to queue requests when underlying framework does not support queueing?

£可爱£侵袭症+ 提交于 2020-01-06 10:09:30
问题 I feel my question is really n00b; apologies if I don't word it clearly :/ In my project I'm using a 3rd party framework that fetches some data for me using asynchronous NSURLRequests (RESTful API). When the data is received and ready, delegate function didReceiveResponse is called. On error case didFailWithError is called. The problem is: framework cannot queue requests, so if I call request methods sequentially I only receive the response for the last request issued. Now the issue is that I

How to get UITableViewCell images to update to downloaded images without having to scroll UITableView

自作多情 提交于 2020-01-06 02:30:11
问题 I'm trying to pull my own flavor of the usual UITableView + async download + cache technique. What I'm doing is, for each cell that gets dequeued in cellForRowAtIndexPath: 1-Check if it's corresponding thumbnail image is already 'cached' in /Library/Caches 2-If it is, just use that. 3-If not, load a default image and enqueue an NSInvocationOperation to take care of it: 4a-The NSInvocationOperation gets the image from a remote server 4b-Does the UIGraphicsBeginContext thing to scale down the

Delegate method not being called

本小妞迷上赌 提交于 2020-01-05 05:08:27
问题 I am making an OpenSource (github) helper class for downloading images asynchronously (I had major trouble with). However, I have delegate methods set up to alert the delegate that a image has finished downloading. The problem is that the delegate method is not getting called. I am setting the delegate and everything, but I don't have a clue why the problem is occurring. Please take a look at my code! I have only posted the relevant code. MKAsyncImageDownloader.h @protocol