Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Last active December 10, 2015 13:28
Show Gist options
  • Save ChrisRisner/4441051 to your computer and use it in GitHub Desktop.
Save ChrisRisner/4441051 to your computer and use it in GitHub Desktop.
iOS Day 28
- (void)backgroundDone {
NSLog(@"Done");
}
- (void)backgroundDone {
NSLog(@"Done");
[self.indicator stopAnimating];
}
- (IBAction)tappedProcessStuff:(id)sender {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSLog(@"Start");
//Do EXTREME PROCESSING!!!
for (int i = 0; i< 100; i++) {
[NSThread sleepForTimeInterval:.05];
NSLog(@"%i", i);
}
dispatch_async(dispatch_get_main_queue(), ^{
[self backgroundDone];
});
});
}
- (IBAction)tappedProcessStuff:(id)sender {
[self.indicator startAnimating];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSLog(@"Start");
//Do EXTREME PROCESSING!!!
for (int i = 0; i< 100; i++) {
[NSThread sleepForTimeInterval:.05];
NSLog(@"%i", i);
}
dispatch_async(dispatch_get_main_queue(), ^{
[self backgroundDone];
});
});
}
- (IBAction)tappedProcessStuff:(id)sender {
[self.indicator startAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSLog(@"Start");
//Do EXTREME PROCESSING!!!
for (int i = 0; i< 100; i++) {
[NSThread sleepForTimeInterval:.05];
NSLog(@"%i", i);
dispatch_async(dispatch_get_main_queue(), ^{
[self updateProgressBar:i];
});
}
dispatch_async(dispatch_get_main_queue(), ^{
[self backgroundDone];
});
});
}
- (void)updateProgressBar:(int)count {
float progress = count/100.0;
[self.progressBar setProgress:progress];
}
@interface ViewController : UIViewController
- (IBAction)tappedProcessStuff:(id)sender;
@end
@interface ViewController : UIViewController
- (IBAction)tappedProcessStuff:(id)sender;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *indicator;
@end
@interface ViewController : UIViewController
- (IBAction)tappedProcessStuff:(id)sender;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *indicator;
@property (weak, nonatomic) IBOutlet UIProgressView *progressBar;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment