Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Created December 19, 2012 06:26
Show Gist options
  • Save ChrisRisner/4334809 to your computer and use it in GitHub Desktop.
Save ChrisRisner/4334809 to your computer and use it in GitHub Desktop.
iOS Day 23
- (IBAction)tappedProcessInBackground:(id)sender {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
//Do EXTREME PROCESSING!!!
for (int i = 0; i< 100; i++) {
[NSThread sleepForTimeInterval:.05];
NSLog(@"%i", i);
}
});
}
- (IBAction)tappedProcessInBackground:(id)sender {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
//Do EXTREME PROCESSING!!!
for (int i = 0; i< 100; i++) {
[NSThread sleepForTimeInterval:.05];
NSLog(@"%i", i);
}
dispatch_async(dispatch_get_main_queue(), ^{
[self updateLabelWhenBackgroundDone];
});
});
}
- (IBAction)tappedProcessInForeground:(id)sender {
for (int i = 0; i< 100; i++) {
[NSThread sleepForTimeInterval:.05];
NSLog(@"%i", i);
}
}
- (IBAction)tappedUpdateLabel:(id)sender {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm:ss"];
NSString *stringFromDate = [formatter stringFromDate:[NSDate date]];
self.lblInfo.text = [stringFromDate stringByAppendingFormat:@"\n%@", self.lblInfo.text];
}
- (void)updateLabelWhenBackgroundDone {
self.lblInfo.text = [@"Background Done!" stringByAppendingFormat:@"\n%@", self.lblInfo.text];
}
@interface ViewController : UIViewController
- (IBAction)tappedProcessInForeground:(id)sender;
- (IBAction)tappedUpdateLabel:(id)sender;
- (IBAction)tappedProcessInBackground:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *lblInfo;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
for (int i = 0; i< 100; i++) {
[NSThread sleepForTimeInterval:.05];
NSLog(@"%i", i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment