grand-central-dispatch

How to work with NSOperationQueue and NSBlockOperation with dispatch gcd?

两盒软妹~` 提交于 2019-12-12 03:17:40
问题 Here is the code @interface ViewController () @property (nonatomic, strong) NSOperationQueue *queue; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _queue = [[NSOperationQueue alloc] init]; NSBlockOperation *aBlockOperation = [[NSBlockOperation alloc] init]; __weak NSBlockOperation* aWeakBlockOperation = aBlockOperation; [aBlockOperation addExecutionBlock:^{ NSLog(@"queue should still have the operation. And it does. yay!: %@", [_queue operations]); // This

EXC_BAD_ACCESS for an object created inside a Block

為{幸葍}努か 提交于 2019-12-12 01:42:12
问题 I have always been nervous when it comes to blocks and GCD because my mind tells me that it looks very complex! I am getting a crash inside a block which ideally looks alright to me: #pragma mark - -(void)fetchOrdersListWithInfoDict:(NSDictionary*)infoDict completionBlock:(CompletionBlock)completionBlock errorBlock:(ErrorBlock)errorBlock { __weak VTVehicleServiceNetworkManager *weakSelf = self; TaskBlock fetchOrdersListTaskBlock = ^() { __block __strong HLOrdersDataProvider

Can I use dispatch group not in a loop?

送分小仙女□ 提交于 2019-12-12 01:14:58
问题 Say I have 3 different asynchronous tasks I want to get done before calling some function. I'm aware of using dispatch groups to do such a thing if those tasks were in a loop, var dispatchGroup = DispatchGroup() for task in tasks { dispatchGroup.enter() DoSomeTask { (error, ref) -> Void in dispatchGroup.leave() } } dispatchGroup.notify(queue: DispatchQueue.main, execute: { DoSomeFunction() }) However, I'm confused on how you'd do this if those tasks were all in the same function but didn't

Wrong images are showing up in UITableviewcell

你说的曾经没有我的故事 提交于 2019-12-12 00:56:57
问题 I am using GCD to load images from web into my UITableViewCell . But, wrong images are showing up. Here is code: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; UITableViewCell *cell = [self.newsTable dequeueReusableCellWithIdentifier:@"newsTableCell"]; NSString *user = [usernames objectAtIndex:[indexPath row]]; NSString *stat = [statistics objectAtIndex:[indexPath

Load Large Data from multiple tables in parallel using multithreading

人走茶凉 提交于 2019-12-12 00:05:23
问题 I'm trying load data about 10K records from 6 different tables from my Ultralite DB. I have created different functions for 6 different tables. I have tried to load these in parallel using NSInvokeOperations, NSOperations, GCD, Subclassing NSOperation but nothing is working out. Actually, loading 10K from 1 table takes 4 Sec, and from another 5 Sec, if i keep these 2 in queue it is taking 9 secs. This means my code is not running in parallel. How to improve performance problem? 回答1: There may

working with variables from dispatch_async

亡梦爱人 提交于 2019-12-11 20:53:37
问题 I have a method which downloads some pics from a server. I had the buffer for the downloaded data defined withing async block (NSMutableArray *imgtmp) but haven't figured out how to get the array back out of there. What's the best way to access imgtmp in order to return it's contents, or set an instance variable from it? I've been looking in the Apple Block docs but I must not be in the right section. Do I need to declare imgtmp using the __block keyword somehow? I tried that but imgtmp was

Uploading Big Image In Background Thread. [closed]

 ̄綄美尐妖づ 提交于 2019-12-11 19:45:49
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I need to upload an Image To webservice. Below is the code snippet i have return to upload an image. The image size is very big (around 6Mb). I am Uploading that Image in Background Thread using GCD. if([VSCore

How to create thread to checking time?

眉间皱痕 提交于 2019-12-11 19:11:32
问题 I have to setting a time to check for update data from server 2times a day, suppose 9AM and 9PM, but i don't know the way to do that. Create a thread, run every-time and check time current time with setting,if they are equal,so do task? This way is good? I think that's bad performance. 回答1: Use thread but instead of checking every sec, if it is equal. You could use NSNotification. When the time is the same, it will send a notification to get the data. You can read this: iOS timed background

NSFileHandle writeData synchronously delaying main thread operations

旧时模样 提交于 2019-12-11 18:54:28
问题 I have a custom implementation of a logger, which logs the actions and operations in my app. A strong NSString reference is living in one of my Singleton Classes. I call a method named " -(void)writeToFile: (BOOL) rightNow ", whenever I need to log something. This method also lives in that Singleton class. Yes passed to rightNow , will trigger the immediate call to writeData: on NSFileHandle, forcing the NSString to be written to the file and emptying the NSString afterwards. No, will only

NSOperationQueue seems to slow performance

南笙酒味 提交于 2019-12-11 18:24:35
问题 I am new to NSOperationQueue, but in a current project I need a way to cancel an asynchronous operation when it times out. My original code uses GCD and works. Here it is: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),^{ rg = [[RiverGauge alloc] initWithStationInfo:[station id] forHistoryInHours:48 inThisFormat:nil]; dispatch_async(dispatch_get_main_queue(), ^{ [hud removeFromSuperview]; UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];