Created
December 19, 2012 06:26
-
-
Save ChrisRisner/4334809 to your computer and use it in GitHub Desktop.
iOS Day 23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
}); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)tappedProcessInForeground:(id)sender { | |
for (int i = 0; i< 100; i++) { | |
[NSThread sleepForTimeInterval:.05]; | |
NSLog(@"%i", i); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)updateLabelWhenBackgroundDone { | |
self.lblInfo.text = [@"Background Done!" stringByAppendingFormat:@"\n%@", self.lblInfo.text]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface ViewController : UIViewController | |
- (IBAction)tappedProcessInForeground:(id)sender; | |
- (IBAction)tappedUpdateLabel:(id)sender; | |
- (IBAction)tappedProcessInBackground:(id)sender; | |
@property (weak, nonatomic) IBOutlet UILabel *lblInfo; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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