dispatch-async

How does a serial dispatch queue guarantee resource protection?

和自甴很熟 提交于 2019-12-12 09:56:37
问题 //my_serial_queue is a serial_dispatch_queue dispatch_async(my_serial_queue, ^{ //access a shared resource such as a bank account balance [self changeBankAccountBalance]; }); If I submit 100 tasks that each access and mutate a bank account balance, I understand that a serial queue will execute each task sequentially, but do these tasks finish sequentially as well when using dispatch_async? What if task #23 that I submit asynchronously to the serial queue takes a really long time to finish?

Forcing the order of execution using dispatch_sync

半腔热情 提交于 2019-12-11 07:58:55
问题 My library exposes 2 APIs as follows to: -(void) createFile{ dispatch_sync(queueSerial, ^{ //B1 [fileObj createFileInfo:file completion:^(NSError *error){ //execute completion block C1 }]; }); } -(void) readFile:(NSData*)timeStamp{ dispatch_async(queueSerial, ^{ //B2 [fileObj readFileInfo:fileName completion:^(NSError *error) { dispatch_async(queueSerial2, ^{ //execute completion block C2 }); }] }); } Both readFile and createFile are asynchronous methods. I usually recommend to the people

how can I trace back beyond dispatch_async when debugging an iOS program?

心不动则不痛 提交于 2019-12-11 02:23:31
问题 I wonder if anyone knows how can I trace back beyond dispatch_async when debugging my iOS program. My program constant crash at two spots: in buffer_is_unused, as shown in and , and in release_shmem_bitmap, as shown in and . None of this happens at the main thread, and on the thread-local stack there is almost nothing except some dispatch_async and pthread jobs. Given my configuration of XCode, it gives me almost no information on who called this dispatched_async. I googled "release_shmem

ios 10+, Swift 3+ - Cannot dismiss UIAlertController from Singleton instance

回眸只為那壹抹淺笑 提交于 2019-12-11 00:15:08
问题 I have created an overlay to run while I run an async data grab to the server so that users won't continue pressing buttons in the UI until the data grab is done. I have put the function into a global singleton class and I call it while passing in a bool to say whether or not I want to show or hide. I can get it to show but I cannot get it to hide. Here is the code: class DataModel { static let sharedInstance = DataModel() func accessNetworkData(vc: UIViewController, params: [String:Any],

Calling NSURLConnection inside dispatch_async and reading didReceiveResponse in mainRunLoop in iPhone development

元气小坏坏 提交于 2019-12-10 20:57:26
问题 What I am trying to do is getting response for following method - (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { } after calling this NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [conn scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; [conn start]; inside a dispatch_async(); But the connection method is not calling. But when I run the NSURLConnection code outside the dispatch

Saving URL data to a variable

江枫思渺然 提交于 2019-12-10 11:55:26
问题 So I am trying to get a simple string of data back from a RESTful API. Here is what a response looks like: Hello It is not formatted in XML or JSON or anything just a simple string because only one word is being passed back at a time. So here is what my swift looks like: let task = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in if error != nil { println("error: \(error.localizedDescription): \(error.userInfo)") } var withNewLine:NSString = NSString(data:

Crashed: com.apple.root.default-qos

倾然丶 夕夏残阳落幕 提交于 2019-12-10 02:19:12
问题 I have a fairly simple app that parses a RSS feed and shows it's content in a table view. It's available on the App Store. I have Crashlytics crash reporting integrated. I recently received two reports. These are a little difficult to decipher. This has occurred in an iPhone 6 running iOS 10.2.1. This is from an iPhone 5 running iOS 10.2.1. Even though it says it's crashing due to privacy violations, I'm not accessing any services that requires permission in my app. Also searching on com

How to convert (OS_dispatch_data *) 5018112 bytes into NSData to put into UIImage

我的未来我决定 提交于 2019-12-09 09:23:29
问题 I've been looking for an answer to this and some seem like they might be what I need but I'm not sure. I found this Question #9152851 and this Question #2617625 and poked around on a bunch of links but I need some direction here. Essentially, I'm dispatching an async call to process an image using OpenCV. You can see by the code here that I'm turning it into NSData * before sending it back to my delegate. NSData *proccessedData = [NSData dataWithBytes:processedImage.data length:

How can i wait to receive a response from a DispatchWorkItem before moving on to the next request or next DispatchWorkItem in a Dispatch Queue

走远了吗. 提交于 2019-12-08 12:17:47
问题 I have an array of dispatch workItems, how to wait until one work is completed before i move on to the next work in the queue? func AsyncCalls(statusHandler: @escaping (String) -> Void){ var dispatchWorkItems : [DispatchWorkItem] = [] let categoryWorkItem = DispatchWorkItem { main { return statusHandler("Loading categories ") } self.modelView.getCategories(completion: { data,error in main { if data.isEmpty { return statusHandler("\(error )") }else{ return statusHandler("Done loading

Does dispatch_after block the main thread?

穿精又带淫゛_ 提交于 2019-12-07 14:26:08
问题 I'm setting a timer so that after a second passes I reset a value for my keyboard extension. The problem is that I feel like the following call is stalling my UI: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [self resetDoubleTapBool]; }) Is there an asynchronous way of doing this, or a better way in general? Thanks! 回答1: The dispatch_after() call itself does not block. At (or shortly after) the appointed time, the block will be submitted to