Skip to content

Commit 929bf68

Browse files
committed
Merge pull request #3 from objectiveSee/arc
Converted to ARC.
2 parents 3699b5d + 36905de commit 929bf68

6 files changed

Lines changed: 21 additions & 51 deletions

File tree

DRKonamiCode.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
3098B2E71504515300F743BD /* Debug */ = {
227227
isa = XCBuildConfiguration;
228228
buildSettings = {
229+
CLANG_ENABLE_OBJC_ARC = YES;
229230
GCC_PRECOMPILE_PREFIX_HEADER = YES;
230231
GCC_PREFIX_HEADER = "DRKonamiCode-Prefix.pch";
231232
INFOPLIST_FILE = "DRKonamiCode-Info.plist";
@@ -237,6 +238,7 @@
237238
3098B2E81504515300F743BD /* Release */ = {
238239
isa = XCBuildConfiguration;
239240
buildSettings = {
241+
CLANG_ENABLE_OBJC_ARC = YES;
240242
GCC_PRECOMPILE_PREFIX_HEADER = YES;
241243
GCC_PREFIX_HEADER = "DRKonamiCode-Prefix.pch";
242244
INFOPLIST_FILE = "DRKonamiCode-Info.plist";

Sources/DRAppDelegate.m

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,12 @@ @implementation DRAppDelegate
1313
@synthesize window = _window;
1414
@synthesize viewController = _viewController;
1515

16-
- (void)dealloc
17-
{
18-
[_window release];
19-
[_viewController release];
20-
[super dealloc];
21-
}
2216

2317
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2418
{
25-
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
19+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
2620

27-
self.viewController = [[[DRViewController alloc] initWithNibName:@"DRViewController" bundle:nil] autorelease];
21+
self.viewController = [[DRViewController alloc] initWithNibName:@"DRViewController" bundle:nil];
2822
self.window.rootViewController = self.viewController;
2923
[self.window makeKeyAndVisible];
3024
return YES;

Sources/DRKonamiGestureRecognizer.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
/**
9-
DRKonamiGestureProtocol is optional!
9+
DRKonamiGestureProtocol is optional! If you are using the delegate then you must implement all of the required methods.
1010
1111
The Konami Gesture protocol implements communication between the gesture recognizer and the delegate when the A+B+Enter action is required to complete the gesture. If the A+B+Enter sequence is not used then none of the protocol methods are required.
1212
*/
@@ -53,27 +53,21 @@ typedef enum DRKonamiGestureState
5353
@todo Reset the state of self.konamiState on gesture fails due to timeout between swipes in sequence.
5454
*/
5555
@interface DRKonamiGestureRecognizer : UIGestureRecognizer
56-
{
57-
NSDate* _lastGestureDate;
58-
CGPoint _lastGestureStartPoint;
59-
BOOL _requiresABEnterToUnlock;
60-
id<DRKonamiGestureProtocol> _konamiDelegate;
61-
}
6256

6357
/**
6458
Indicates whether the konami sequence requires A+B+Enter to finish the sequence. If NO then the sequence is finished successfully after the final RIGHT gesture. Default value is NO.
6559
*/
66-
@property (nonatomic, assign, readwrite) BOOL requiresABEnterToUnlock;
60+
@property (nonatomic, readwrite) BOOL requiresABEnterToUnlock;
6761

6862
/**
6963
The current state of the konami gesture.
7064
*/
71-
@property (nonatomic, assign, readonly) DRKonamiGestureState konamiState;
65+
@property (nonatomic, readonly) DRKonamiGestureState konamiState;
7266

7367
/**
7468
The delegate of the gesture. If the delegate is set then the delegate must conform to DRKonamiGestureRecognizer. The delegate does not need to be used if requiresABEnterToUnlock is set to NO.
7569
*/
76-
@property (nonatomic, assign, readwrite) id<DRKonamiGestureProtocol> konamiDelegate;
70+
@property (nonatomic, weak, readwrite) id<DRKonamiGestureProtocol> konamiDelegate;
7771

7872
/**
7973
Methods used by the delegate (if delegate exists) to specify when the A, B, and Enter actions occur.

Sources/DRKonamiGestureRecognizer.m

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,14 @@
3030
///////////////////////////////////////////////////////////////
3131

3232
@interface DRKonamiGestureRecognizer ()
33-
@property (nonatomic, assign, readwrite) DRKonamiGestureState konamiState;
34-
@property (nonatomic, retain, readwrite) NSDate* lastGestureDate;
35-
@property (nonatomic, assign, readwrite) CGPoint lastGestureStartPoint;
33+
@property (nonatomic, readwrite) DRKonamiGestureState konamiState;
34+
@property (nonatomic, strong, readwrite) NSDate* lastGestureDate;
35+
@property (nonatomic, readwrite) CGPoint lastGestureStartPoint;
3636
@end
3737

3838
///////////////////////////////////////////////////////////////
3939

4040
@implementation DRKonamiGestureRecognizer
41-
@synthesize konamiState = _konamiState;
42-
@synthesize lastGestureDate = _lastGestureDate;
43-
@synthesize lastGestureStartPoint = lastGestureStartPoint;
44-
@synthesize requiresABEnterToUnlock = _requiresABEnterToUnlock;
45-
@synthesize konamiDelegate = _konamiDelegate;
4641

4742
#pragma mark -
4843
#pragma mark Lifecycle
@@ -52,28 +47,15 @@ - (id) initWithTarget:(id)target action:(SEL)action
5247
self = [super initWithTarget:target action:action];
5348
if ( self != nil )
5449
{
55-
_konamiState = DRKonamiGestureStateNone;
56-
_lastGestureDate = [NSDate new];
57-
_lastGestureStartPoint = CGPointZero;
58-
_requiresABEnterToUnlock = NO;
59-
_konamiDelegate = nil;
50+
self.konamiState = DRKonamiGestureStateNone;
51+
self.lastGestureDate = [NSDate new];
52+
self.lastGestureStartPoint = CGPointZero;
53+
self.requiresABEnterToUnlock = NO;
6054
self.cancelsTouchesInView = NO;
6155
}
6256
return self;
6357
}
6458

65-
- (id) init
66-
{
67-
NSLog(@"Invalid initalizer: %s", __FUNCTION__);
68-
return nil;
69-
}
70-
71-
- (void) dealloc
72-
{
73-
self.lastGestureDate = nil;
74-
[super dealloc];
75-
}
76-
7759
#pragma mark -
7860
#pragma mark Touches
7961

@@ -124,7 +106,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
124106
[self setState:UIGestureRecognizerStateFailed];
125107
return;
126108
}
127-
self.lastGestureDate = [[NSDate new] autorelease]; // autorelease because it's retained twice (new & in setter)
109+
self.lastGestureDate = [NSDate new];
128110
UITouch *touch = [touches anyObject];
129111
UIView *view = [self view];
130112
self.lastGestureStartPoint = [touch locationInView:view];
@@ -266,7 +248,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
266248
}
267249

268250
self.konamiState++;
269-
self.lastGestureDate = [[NSDate new] autorelease]; // autorelease because it's retained twice (new & by setter)
251+
self.lastGestureDate = [NSDate new]; // autorelease because it's retained twice (new & by setter)
270252

271253
[self setState:UIGestureRecognizerStateChanged];
272254

Sources/DRViewController.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
DRKonamiGestureRecognizer* _konamiGestureRecognizer;
1414

1515
@protected
16-
UIView* _NESControllerView;
17-
UILabel *_statusLabel;
16+
UIView* __weak _NESControllerView;
17+
UILabel *__weak _statusLabel;
1818
}
1919

20-
@property (nonatomic, readonly) IBOutlet UIView *NESControllerView;
21-
@property (nonatomic, readonly) IBOutlet UILabel *statusLabel;
20+
@property (weak, nonatomic, readonly) IBOutlet UIView *NESControllerView;
21+
@property (weak, nonatomic, readonly) IBOutlet UILabel *statusLabel;
2222
@property (nonatomic, readonly) DRKonamiGestureRecognizer* konamiGestureRecognizer;
2323

2424
- (IBAction)aButtonWasPressed:(id)sender;

Sources/DRViewController.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ - (void)viewDidLoad
3838
- (void)viewDidUnload
3939
{
4040
[self.view removeGestureRecognizer:self.konamiGestureRecognizer];
41-
[_konamiGestureRecognizer release];
4241
_konamiGestureRecognizer = nil;
4342
[super viewDidUnload];
4443
}
@@ -98,7 +97,6 @@ - (void)_konamiGestureRecognized:(DRKonamiGestureRecognizer*)gesture
9897
{
9998
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Konami!" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss",nil];
10099
[alert show];
101-
[alert release];
102100
}
103101
else if ( gesture.state == UIGestureRecognizerStateChanged )
104102
{

0 commit comments

Comments
 (0)