Permalink
Browse files

Converted sample project to ARC. Lockbox updated to work in ARC and n…

…on-ARC environments automagically.
  • Loading branch information...
1 parent 5d32b1b commit 7f5393768d89060a9d232dd2ece09d33a114d0bf @granoff committed Jul 24, 2012
@@ -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 */
@@ -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";
@@ -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";
@@ -285,6 +287,7 @@
2D0B9E7F1540556E00E5BE71 /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
@@ -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;
}
@@ -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
@@ -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
{
View
@@ -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);
@@ -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;
View
@@ -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'

0 comments on commit 7f53937

Please sign in to comment.