grand-central-dispatch

UITableViewCell textLabel, does not update until a scroll, or touch happens, while using GCD

隐身守侯 提交于 2019-12-03 10:56:51
Can someone help me figure this out please? My UITableViewCell textLabel , does not update until I scroll , or touch it. The ViewController loads, it shows the right amount of cells . But the content is blank. I have to touch it or scroll to make my textLabel appear. Am I doing something wrong here? - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle

What happens to tasks in dispatch queues when an app enters inactive/background/suspended states in iOS?

試著忘記壹切 提交于 2019-12-03 10:54:40
I've been scouring Apple's documentation on application states and Grand Central Dispatch, but I haven't found a good answer to this question. According to Apple's documentation, on iOS 4.0: The application is in the background but is not executing code. The system moves an application to this state automatically and at appropriate times. While suspended, an application is essentially freeze-dried in its current state and does not execute any code. During low-memory conditions, the system may purge suspended applications without notice to make more space for the foreground application. So

In unit test, execute the block passed in queue with dispatch_asyc

[亡魂溺海] 提交于 2019-12-03 10:13:38
If I dispatch_async a block on main queue like this: -(void) myTask { dispatch_async(dispatch_get_main_queue(), ^{ [self.service fetchData]; }); } In unit test, I can execute the block passed in main queue by manually run the main loop like this: -(void)testMyTask{ // call function under test [myObj myTask]; // run the main loop manually! [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]; // now I can verify the function 'fetchData' in block is called ... } Now, I have another similar function which dispatch block to an sequential queue other than main queue: -

dispatch_async block on main queue is never execeuted

人盡茶涼 提交于 2019-12-03 10:13:08
I have an app that uses a connection queue that handles the connections on a background thread. Each connection sends a JSON post, then when it receives a success, saves some objects into coredata. Once all connections are complete, i call a dispatch_async on the main thread to call a finished method. However, under very specific conditions of data im sending/saving, I've noticed the dispatch_async block to the main thread never gets called, and the app screen freezes, all execution stops, and the app sits idle with a frozen screen. processing power according to xcode is 0%. Here is method

UITableView insertRowsAtIndexPaths:WithRowAnimation without freeze UI

半腔热情 提交于 2019-12-03 10:09:30
I try to understand what is the best practice to use when I work with UITableView with large number of row to insert when the table is visible. This is my behavior: I have one UITableView and one Thread that try to insert a data into this table. I think that make a [UITableView reloadData] is a poor solution for the performance aspect, and I know that UIKit operation are be carried on main thread, for this reason when the datasource update is completed I tried to send a NSNotification to make a UITableView update operation (beginUpdate - insertRowAtIndex - endUpdate) on the main thread, but

How can I replace deprecated method dispatch_get_current_queue() from ios5 to ios6 in iphone? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-03 09:21:06
This question already has an answer here: Alternatives to dispatch_get_current_queue() for completion blocks in iOS 6? 7 answers I am developing a chat application using xmppframework in IOS 5; it works perfectly. But I updated my xcode to 4.5.1, ios5 to IOS 6 and my mac OS to 10.7.5, and the project did not work due to deprecated issues. I replaces all methods with new methods in ios 6 except this one: dispatch_get_current_queue() How can I replace this method in IOS 6? It depends what you need to achieve with this call. Apple states that it should be used for debugging anyway. Perhaps the

HTTP Long Polling in Swift

做~自己de王妃 提交于 2019-12-03 09:16:48
I am trying to implement a long-polling solution in Swift using iOS 8+. While the solution undoubtedly works and leaves the main thread free for UI interactions, the memory usage climbs continuously so I am obviously doing something wrong. The class I have written is as follows: enum LongPollError:ErrorType{ case IncorrectlyFormattedUrl case HttpError } public class LongPollingRequest: NSObject { var GlobalUserInitiatedQueue: dispatch_queue_t { return dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0) } var GlobalBackgroundQueue: dispatch_queue_t { return dispatch_get_global

loading image in UITableViewCell asynchronously

主宰稳场 提交于 2019-12-03 09:10:09
What is the super very easy way to load the image in the UITableViewCell asynchronously say given a imageURL without having to subclassing the UITableViewCell, i.e: standard UITableViewCell The easiest way I know is to use SDWebImage library. Here is a link that explains how to utilize the SDWebImage library to load avatars asynchronously. SDWebImage is an extension to the ImageView. Here is the usage: // load the avatar using SDWebImage [cell.imageView setImageWithURL:[NSURL URLWithString:tweet.profileImageUrl] placeholderImage:[UIImage imageNamed:@"grad_001.png"]]; And here is the referenced

Write macros for GCD calls?

落花浮王杯 提交于 2019-12-03 08:29:30
I'd like to create a macro for GCD calls like for example: dispatch_async(dispatch_get_main_queue(), ^{ stuff.... }); the macro could look something like this: main(^{...})? Not sure how to write it. Any suggestion? thank you You can define macros like this: #define ASYNC(...) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ __VA_ARGS__ }) #define ASYNC_MAIN(...) dispatch_async(dispatch_get_main_queue(), ^{ __VA_ARGS__ }) First one will invoke the code asynchronously on unspecified thread (do all long running tasks using it) and the second one will invoke the

c# dispatch queues like in objective c

我们两清 提交于 2019-12-03 08:27:34
I want to mimic the behavior of objective-c dispatch queues in c#. I see that there is a task parallel library but I really don't understand how to use it and was hoping to get some explanation on how. In objective c i would do something like: -(void)doSomeLongRunningWorkAsync:(a_completion_handler_block)completion_handler { dispatch_async(my_queue, ^{ result *result_from_long_running_work = long_running_work(); completion_handler(result_from long_running_work); }); } -(void)aMethod { [self doSomeLongRunningWorkAsync:^(result *) { // the completion handler do_something_with_result_from_long