nsoperation

NSOperationQueue and NSFetchedResultsController

女生的网名这么多〃 提交于 2020-01-04 11:05:29
问题 i use a combination of queue and resultscontroller to update and display some coredata objects. in my uitableviewcontroller i call every X second a method in my main controller object. [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(test:) userInfo:nil repeats:YES]; } - (void)test:(NSTimer*)theTimer { [[MainController instance] updatePersons]; } In this method a custom NSOperation object will be added to my main Q. - (BOOL)updatePersons { UpdatePersonsOperation* u = [

Iphone — Confused about leaks within my NSOperation

自作多情 提交于 2020-01-03 05:56:13
问题 My app has an NSOperation class called ServerRequest that handles networking tasks. According to instruments, it is leaking like crazy. Additionally, instruments says the code that builds the request is leaking, even though that is not an NSOperation. But I have followed Apple's advice in terms of setting up an autorelease pool, so I don't understand what could be the matter. Can anyone help? A portion of my code is below: -(void) main { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]

iOS - Async NSURLConnection inside NSOperation

守給你的承諾、 提交于 2020-01-02 02:43:06
问题 I know this question was asked many times on SO, but I didn't manage to make it work in my project... So, I want to subclass NSOperation and make it download a file using NSURLConnection . What is the right way to do it? here is my code which doesn't work: First, I'm adding all my operations in a loop: DownloadFileOperation *operation; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; for (int i=0; i<10; i++) { operation = [[DownloadFileOperation alloc] init]; operation.urlString =

NSAutoreleasePool. When is it appropriate to create a new autorelease pool?

拟墨画扇 提交于 2020-01-01 10:56:25
问题 On iOS/CocoaTouch I often see code that creates a new instance of NSAutoreleasePool within a method. I recently saw one within an NSOperation. What are the ground rules for setting up a new instance of NSAutoreleasePool? Why is this preferable to simply relying on the pre-existing release pool created in main.m? Thanks, Doug 回答1: You can use a new autorelease pool whenever you want, but it is not always beneficial. It is required whenever you start a new thread or objects autoreleased in that

Use of delegates in NSOperation

痴心易碎 提交于 2020-01-01 03:25:09
问题 I am trying to make use of CLLocationManager in an NSOperation . As part of this I require the ability to startUpdatingLocation then wait until a CLLocation is received before completing the operation. At present I have done the following, however the delegate method never seems to be called. Please can someone advise what the issue is? - (void)main { @autoreleasepool { if (self.isCancelled) return; // Record the fact we have not found the location yet shouldKeepLooking = YES; // Setup the

NSOperation blocks UI painting?

 ̄綄美尐妖づ 提交于 2019-12-31 13:13:41
问题 I'm after some advice on the use of NSOperation and drawing: I have a main thread create my NSOperation subclass, which then adds it to an NSOperationQueue . My NSOperation does some heavy processing, it is intended to loop in its main() method for several minutes, constantly processing some work, but for now I just have a while() loop with a sleep(1) inside, which is set to go around just 5 times (for testing). The main (original) thread which spawns this NSOperation is responsible for

NSOperation using GCD, ensure all on the same thread

烈酒焚心 提交于 2019-12-25 06:05:11
问题 I have a 'concurrent' NSOperation , and during it's work it uses some controller classes that internally use GCD. When these controller classes return with their completion block, the completion block is on another thread. I know I could store the current thread in the operation start method and run performSelectorOnThread: , but ideally I would like to wrap the completion in a GCD block and dispatch onto the same thread as the operation started on. Is this even possible with GCD, as I can

NSOperationQueue,NSOperation

给你一囗甜甜゛ 提交于 2019-12-24 10:20:10
问题 I m new to iphone. where i get examples for NSOperationQueue , NSOperation ? What is the advantage of NSOperationQueue , NSOperation over thread? Thanks 回答1: Read the docs. They are really good at explaining and giving examples http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationObjects/OperationObjects.html%23//apple_ref/doc/uid/TP40008091-CH101-SW1 NSOperation is easier to manage than NSThread. 回答2: Higher level of abstraction: That

Issues with NSOperationQueue and dealloc being called and crashing App

家住魔仙堡 提交于 2019-12-24 07:03:27
问题 I've created an NSOperation in the queue like so: ImageLoadingOperation *operation = [[ImageLoadingOperation alloc] initWithImageURL:url target:self action:@selector(didFinishLoadingImageWithResult:)]; [operationQueue addOperation:operation]; [operation release]; And this works fine but if the view gets popped before the operation finishes the App crashes with "EXC_BAD_ACCESS" I've tried to cancel the the operation Queue by calling cancelAllOperations but as its already in process it doesn't

How do I wait until an NSOperationQueue has finished in a Unit Test?

南笙酒味 提交于 2019-12-24 06:31:38
问题 The Problem I have an NSOperationQueue called logEntryGeneratorQueue I want to wait until all operations on the queue have completed If I use: [logEntryGeneratorQueue waitUntilAllOperationsAreFinished]; it works fine if the thread adding to the queue is in the background itself. However, if I'm running this code via a unit test, it'll be running on the main thread. So I came up with this "solution", which I really don't like: if ([NSThread isMainThread]) { while ([[logEntryGeneratorQueue