grand-central-dispatch

queue of AFNetworking requests with dispatch_group_t

谁都会走 提交于 2019-12-11 04:25:53
问题 I want to send messages one by one in a queue. In other words I need to send new request after I get the response of the previous request. I use dispatch_group_t with AFNetworking But it does not work as I expected (I know there are other ways with operationQueue ). Here is my controller: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; dispatch_async(queue, ^{ [self sentTest]; }); } - (void) sentTest{ dispatch_group_t group = dispatch_group_create(); NSLog(@"Start ...

Using dispatch method upload the data based on button action in Iphone

折月煮酒 提交于 2019-12-11 04:08:17
问题 I am new one of using Grand central dispatch. I read the Apple documents about using GCD but still I have no idea about use this method. My thought is I have three type of upload buttons in my view and I clicked the button simultaneously I want to upload the data based on button action using NSURLCOnnection upload the content of data dispatch queue method.How can i do this. Pls help me 回答1: Try reading Mike Ash's blog on grand central dispatch - it will give you a good idea of how to use its

Is this the right way to compare two GCD Queues?

淺唱寂寞╮ 提交于 2019-12-11 03:58:14
问题 Following an earlier question on SO, I'm now looking to compare two different grand central dispatch queues to try and determine if the current code is being run on the main thread or not. My question simply: is this a valid way of achieving this? Or are there some pitfalls of doing this that I haven't considered? if (dispatch_get_current_queue() != dispatch_get_main_queue()) { // We are currently on a background queue } else { // We are on the main queue } Cheers 回答1: Comparing the current

How to debug an iOS app crash at launch time, breakpoint only in assembly file

老子叫甜甜 提交于 2019-12-11 03:38:41
问题 I'am facing an issue with an app currently in development. The problem is that the App crash at launch time when it was in background for a while, and only in that case. Launching the app while it was killed doesn't lead to crash, from debugger or from phone. Launching the app while it was in background for about 5-10 min doesn't lead to crash, while debugging or not. Launching the app while in backgorund for about 15-20 min lead to a crash. Using debugger and breakpoint on exception gave me

Do I need DispatchQueue.main to update UI after an Alamofire request?

风流意气都作罢 提交于 2019-12-11 02:41:37
问题 I'm following a tutorial about working with REST/web requests . In the tutorial, we're working towards a Pokedex app where we fetch Pokemon details from an API using Alamofire , and then displaying that data in our UIs. Here's the related code: typealias DownloadComplete = (Bool) -> () // Model class func downloadPokemonDetails(completed: @escaping DownloadComplete) { Alamofire.request(_pokemonURL).responseJSON { (response) in var success = true if let jsonData = response.result.value as?

Code runs faster when queued synchronously than asynchronously. Shouldn't it be the opposite?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 01:26:15
问题 I am trying to speed up a process that slows down my main thread by distributing it at least across two different cores. The reason I think I can pull this off is that each of the individual operations are independent requiring only two points and a float. However my first stab at is has the code running significantly slower when doing queue.asnc vs queue.sync and I have no clue why! Here is the code running synchronously var block = UnsafeMutablePointer<Datas>.allocate(capacity: 0) var

Delay via GCD vs. sleep()

こ雲淡風輕ζ 提交于 2019-12-11 01:18:29
问题 I have the method in which I need to make a 5 sec delay every time I call it. Firstly I make it with sleep(5); - it worked excellent but I believe - it's not obj-c way, so I tried to write it with GCD help. The first call of this procedure make a delay about 5 sec, but other calls in this queue are going one after one without delay. How to solve this problem? - (void) buyItemAtUUID:(NSString*)UUID { dispatch_barrier_async(dataManagerQueue, ^{ [[UIApplication sharedApplication]

Creating semaphore with initial value of 0 make issues with execution

别来无恙 提交于 2019-12-11 00:47:59
问题 I'm learning GCD and got question about semaphore. Here is my code: class ViewController: UIViewController { var semaphore: dispatch_semaphore_t! = nil override func viewDidLoad() { super.viewDidLoad() semaphore = dispatch_semaphore_create(0) dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)) { print("Entering") self.semaphoreTask() print(self.semaphore.debugDescription) } semaphoreTask() print(semaphore.debugDescription) } func semaphoreTask() { dispatch_semaphore_wait(semaphore

Get GCD label in Swift 3

天大地大妈咪最大 提交于 2019-12-11 00:45:16
问题 I've got some code that gets the label of the current GCD queue for logging purposes that looks like this in Swift 2: if let queueName = String(UTF8String: dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)) where !queueName.isEmpty { detailedMessage += "[" + queueName + "] " } After Xcode 8 converted this to Swift 3, it looks like this: if let queueName = String(validatingUTF8: DISPATCH_CURRENT_QUEUE_LABEL.label), !queueName.IsEmpty { detailedMessage += "[" + queueName + "] " } However

Image loading with GCD receiving memory warning

假装没事ソ 提交于 2019-12-10 23:27:57
问题 I'm developing a photo gallery application using AssetsLibrary to load my device photos. When presenting a random image in another VC I've noticed the following : it takes about 1 or 2 seconds for my full res image to load on the imageView (way much longer than the native photosApp) and I also get from the log "Received memory warning" after loading a few images. If I set my representation to fullScreenImage the warnings stop but I don't want this. What must I change for a smooth performance