Skip to content

Instantly share code, notes, and snippets.

@nolili
Created December 12, 2011 07:49
Show Gist options
  • Save nolili/1465746 to your computer and use it in GitHub Desktop.
Save nolili/1465746 to your computer and use it in GitHub Desktop.
ARC
#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>
@implementation ViewController
{
CMMotionManager *motionManager;
}
- (void)hoge
{
NSLog(@"hoge");
}
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
motionManager = [[CMMotionManager alloc] init];
__weak ViewController *weakSelf = self;
[motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error){
__strong ViewController *strongSelf = weakSelf;
if (strongSelf){
[strongSelf hoge];
}
}];
}
return self;
}
- (void)dealloc
{
[motionManager stopGyroUpdates];
NSLog(@"Dealloc");
}
@end
#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>
@implementation ViewController
{
CMMotionManager *motionManager;
}
- (void)hoge
{
NSLog(@"hoge");
}
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
motionManager = [[CMMotionManager alloc] init];
[motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error){
[self hoge];
}];
}
return self;
}
- (void)dealloc
{
[motionManager stopGyroUpdates];
NSLog(@"Dealloc");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment