Skip to content

Commit

Permalink
Converted sample project to ARC. Lockbox updated to work in ARC and n…
Browse files Browse the repository at this point in the history
…on-ARC environments automagically.
  • Loading branch information
granoff committed Jul 24, 2012
1 parent 5d32b1b commit 7f53937
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
5 changes: 4 additions & 1 deletion LockBox/LockBox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
2D0B9E741540556E00E5BE71 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D0B9E731540556E00E5BE71 /* AppDelegate.m */; };
2D0B9E771540556E00E5BE71 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D0B9E761540556E00E5BE71 /* ViewController.m */; };
2D0B9E7A1540556E00E5BE71 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2D0B9E781540556E00E5BE71 /* ViewController.xib */; };
2D0B9E821540558B00E5BE71 /* Lockbox.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D0B9E811540558B00E5BE71 /* Lockbox.m */; };
2D0B9E821540558B00E5BE71 /* Lockbox.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D0B9E811540558B00E5BE71 /* Lockbox.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
2D0B9E841540565000E5BE71 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D0B9E831540565000E5BE71 /* Security.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -247,6 +247,7 @@
2D0B9E7E1540556E00E5BE71 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "LockBox/LockBox-Prefix.pch";
INFOPLIST_FILE = "LockBox/LockBox-Info.plist";
Expand All @@ -258,6 +259,7 @@
2D0B9E7F1540556E00E5BE71 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "LockBox/LockBox-Prefix.pch";
INFOPLIST_FILE = "LockBox/LockBox-Info.plist";
Expand Down Expand Up @@ -285,6 +287,7 @@
2D0B9E7F1540556E00E5BE71 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
5 changes: 3 additions & 2 deletions LockBox/LockBox/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.viewController = vc;
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
Expand Down
10 changes: 5 additions & 5 deletions LockBox/LockBox/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

@interface ViewController : UIViewController <UITextFieldDelegate>

@property (retain, nonatomic) IBOutlet UITextField *inputTextField;
@property (retain, nonatomic) IBOutlet UIButton *saveButton;
@property (retain, nonatomic) IBOutlet UIButton *fetchButton;
@property (retain, nonatomic) IBOutlet UILabel *fetchedValueLabel;
@property (retain, nonatomic) IBOutlet UILabel *statusLabel;
@property ( nonatomic) IBOutlet UITextField *inputTextField;
@property ( nonatomic) IBOutlet UIButton *saveButton;
@property ( nonatomic) IBOutlet UIButton *fetchButton;
@property ( nonatomic) IBOutlet UILabel *fetchedValueLabel;
@property ( nonatomic) IBOutlet UILabel *statusLabel;

@end
8 changes: 0 additions & 8 deletions LockBox/LockBox/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (void)dealloc {
[inputTextField release];
[saveButton release];
[fetchButton release];
[fetchedValueLabel release];
[statusLabel release];
[super dealloc];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
Expand Down
37 changes: 31 additions & 6 deletions Lockbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,37 @@ +(BOOL)setObject:(NSString *)obj forKey:(NSString *)key
if (!obj) {
NSMutableDictionary *query = [self _query];
[query setObject:hierKey forKey:(id)kSecAttrService];
#if __has_feature(objc_arc)
status = SecItemDelete((__bridge CFDictionaryRef)query);
#else
status = SecItemDelete((CFDictionaryRef)query);
#endif
return (status == errSecSuccess);
}

NSMutableDictionary *dict = [self _service];
[dict setObject: hierKey forKey: (id) kSecAttrService];
[dict setObject: [obj dataUsingEncoding:NSUTF8StringEncoding] forKey: (id) kSecValueData];

#if __has_feature(objc_arc)
status = SecItemAdd ((__bridge CFDictionaryRef) dict, NULL);
#else
status = SecItemAdd ((CFDictionaryRef) dict, NULL);
#endif
if (status == errSecDuplicateItem) {
NSMutableDictionary *query = [self _query];
[query setObject:hierKey forKey:(id)kSecAttrService];
status = SecItemDelete((CFDictionaryRef)query);
#if __has_feature(objc_arc)
status = SecItemDelete((__bridge CFDictionaryRef)query);
#else
status = SecItemDelete((CFDictionaryRef) query);
#endif
if (status == errSecSuccess)
status = SecItemAdd((CFDictionaryRef) dict, NULL);
#if __has_feature(objc_arc)
status = SecItemAdd((__bridge CFDictionaryRef) dict, NULL);
#else
status = SecItemAdd((CFDictionaryRef) dict, NULL);
#endif
}
if (status != errSecSuccess)
NSLog(@"SecItemAdd failed for key %@: %ld", hierKey, status);
Expand All @@ -84,22 +100,31 @@ +(NSString *)objectForKey:(NSString *)key
NSMutableDictionary *query = [self _query];
[query setObject:hierKey forKey: (id)kSecAttrService];

NSData *data = nil;
CFDataRef data = nil;
OSStatus status =
SecItemCopyMatching ( (CFDictionaryRef) query, (CFTypeRef*) &data );
#if __has_feature(objc_arc)
SecItemCopyMatching ( (__bridge CFDictionaryRef) query, (CFTypeRef *) &data );
#else
SecItemCopyMatching((CFDictionaryRef) query, (CFTypeRef *)&data);
#endif
if (status != errSecSuccess)
NSLog(@"SecItemCopyMatching failed for key %@: %ld", hierKey, status);

if (!data)
return nil;

NSString *s = [[NSString alloc]
initWithData: data
initWithData:
#if __has_feature(objc_arc)
(__bridge_transfer NSData *)data
#else
(NSData *)data
#endif
encoding: NSUTF8StringEncoding];

#if !__has_feature(objc_arc)
[s autorelease];
[data autorelease];
CFRelease(data);
#endif

return s;
Expand Down
4 changes: 2 additions & 2 deletions Lockbox.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = 'Lockbox'
s.version = '1.0.5'
s.version = '1.1.0'
s.license = 'MIT'
s.summary = 'Lockbox is an Objective-C utility class for storing data securely in the keychain. Use it to store small, sensitive bits of data securely.'
s.homepage = 'https://github.com/granoff/Lockbox'
s.author = 'Mark H. Granoff'

s.source = { :git => 'https://github.com/granoff/Lockbox.git', :tag => '1.0.5' }
s.source = { :git => 'https://github.com/granoff/Lockbox.git', :tag => '1.1.0' }

s.source_files = 'Lockbox.{h,m}'
s.clean_path = 'LockBox'
Expand Down

0 comments on commit 7f53937

Please sign in to comment.