From da914d9c9ef0306b2a2a888e3b2d71e26f22dd3b Mon Sep 17 00:00:00 2001 From: Erwin Zwart Date: Wed, 25 Sep 2013 14:28:19 +0200 Subject: [PATCH] Converted to Objective-C ARC --- FacebookLikeView/Classes/FacebookLikeView.h | 16 +++++----- FacebookLikeView/Classes/FacebookLikeView.m | 29 +++++++------------ .../project.pbxproj | 24 ++++++++------- .../FacebookLikeViewDemoAppDelegate.m | 8 +---- .../FacebookLikeViewDemoViewController.m | 20 +++++-------- FacebookLikeViewDemo/main.m | 8 ++--- 6 files changed, 43 insertions(+), 62 deletions(-) diff --git a/FacebookLikeView/Classes/FacebookLikeView.h b/FacebookLikeView/Classes/FacebookLikeView.h index a6ac2fa..cbf4dd3 100644 --- a/FacebookLikeView/Classes/FacebookLikeView.h +++ b/FacebookLikeView/Classes/FacebookLikeView.h @@ -13,30 +13,30 @@ @interface FacebookLikeView : UIView // A delegate -@property (assign) IBOutlet id delegate; +@property (unsafe_unretained) IBOutlet id delegate; // The URL to like. This and the following properties map directly to XFBML attributes // described here: https://developers.facebook.com/docs/reference/plugins/like/ -@property (retain) NSURL *href; +@property (strong, nonatomic) NSURL *href; // The style of the Like button and like count. Options: 'standard', 'button_count', and 'box_count'. // You are responsible for sizing your FacebookLikeView appropriately for the layout you choose. -@property (retain) NSString *layout; +@property (strong, nonatomic) NSString *layout; // Specifies whether to display profile photos below the button ('standard' layout only) -@property (assign) BOOL showFaces; +@property (assign, nonatomic) BOOL showFaces; // The verb to display on the button. Options: 'like', 'recommend' -@property (retain) NSString *action; +@property (strong, nonatomic) NSString *action; // The font to display in the button. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana' -@property (retain) NSString *font; +@property (strong, nonatomic) NSString *font; // The color scheme for the like button. Options: 'light', 'dark' -@property (retain) NSString *colorScheme; +@property (strong, nonatomic) NSString *colorScheme; // A label for tracking referrals. -@property (retain) NSString *ref; +@property (strong, nonatomic) NSString *ref; // Load/reload the content of the web view. You should call this after changing any of the above parameters, // and whenever the user signs in or out of Facebook. diff --git a/FacebookLikeView/Classes/FacebookLikeView.m b/FacebookLikeView/Classes/FacebookLikeView.m index 5afb111..537e454 100644 --- a/FacebookLikeView/Classes/FacebookLikeView.m +++ b/FacebookLikeView/Classes/FacebookLikeView.m @@ -10,14 +10,14 @@ @interface FacebookLikeView () -@property (readonly) UIWebView *webView; +@property (strong, nonatomic) UIWebView *webView; @end @implementation NSData (UTF8String) - (NSString*)UTF8String { - return [[[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding] autorelease]; + return [[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding]; } @end @@ -40,29 +40,20 @@ - (id)initWithCoder:(NSCoder *)aDecoder { - (void)dealloc { - [_href release]; - [_layout release]; - [_action release]; - [_font release]; - [_colorScheme release]; - [_ref release]; - // According to SDK doc, UIWebView's delegate must be set to nil before the view is released. - _webView.delegate = nil; - [_webView release]; - - [super dealloc]; + self.webView.delegate = nil; + } - (void)initCommon { - _webView = [[UIWebView alloc] init]; - _webView.opaque = NO; - _webView.backgroundColor = [UIColor clearColor]; - _webView.delegate = self; - [self addSubview:_webView]; + self.webView = [[UIWebView alloc] init]; + self.webView.opaque = NO; + self.webView.backgroundColor = [UIColor clearColor]; + self.webView.delegate = self; + [self addSubview:self.webView]; // Prevent web view from scrolling - for (UIScrollView *subview in _webView.subviews) + for (UIScrollView *subview in self.webView.subviews) if ([subview isKindOfClass:[UIScrollView class]]) { subview.scrollEnabled = NO; subview.bounces = NO; diff --git a/FacebookLikeViewDemo.xcodeproj/project.pbxproj b/FacebookLikeViewDemo.xcodeproj/project.pbxproj index 24af4d6..bee10ab 100644 --- a/FacebookLikeViewDemo.xcodeproj/project.pbxproj +++ b/FacebookLikeViewDemo.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - D307EF6213BB98A6007D866B /* Facebook+ForceDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = D307EF6113BB98A6007D866B /* Facebook+ForceDialog.m */; }; + D307EF6213BB98A6007D866B /* Facebook+ForceDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = D307EF6113BB98A6007D866B /* Facebook+ForceDialog.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; D32BC59413B969FC0069C39F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D32BC59313B969FC0069C39F /* UIKit.framework */; }; D32BC59613B969FC0069C39F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D32BC59513B969FC0069C39F /* Foundation.framework */; }; D32BC59813B969FC0069C39F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D32BC59713B969FC0069C39F /* CoreGraphics.framework */; }; @@ -19,17 +19,17 @@ D32BC5AD13B969FC0069C39F /* FacebookLikeViewDemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D32BC5AB13B969FC0069C39F /* FacebookLikeViewDemoViewController.xib */; }; D32BC5DA13B96AAA0069C39F /* FacebookLikeView.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5BE13B96AAA0069C39F /* FacebookLikeView.m */; }; D32BC5DB13B96AAA0069C39F /* FacebookLikeView.html in Resources */ = {isa = PBXBuildFile; fileRef = D32BC5C013B96AAA0069C39F /* FacebookLikeView.html */; }; - D32BC5DC13B96AAA0069C39F /* Facebook.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5C313B96AAA0069C39F /* Facebook.m */; settings = {COMPILER_FLAGS = "-w"; }; }; + D32BC5DC13B96AAA0069C39F /* Facebook.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5C313B96AAA0069C39F /* Facebook.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; D32BC5DD13B96AAA0069C39F /* FBDialog.bundle in Resources */ = {isa = PBXBuildFile; fileRef = D32BC5C513B96AAA0069C39F /* FBDialog.bundle */; }; - D32BC5DE13B96AAA0069C39F /* FBDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5C713B96AAA0069C39F /* FBDialog.m */; settings = {COMPILER_FLAGS = "-w"; }; }; - D32BC5DF13B96AAA0069C39F /* FBLoginDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5C913B96AAA0069C39F /* FBLoginDialog.m */; settings = {COMPILER_FLAGS = "-w"; }; }; - D32BC5E013B96AAA0069C39F /* FBRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5CB13B96AAA0069C39F /* FBRequest.m */; settings = {COMPILER_FLAGS = "-w"; }; }; - D32BC5E113B96AAA0069C39F /* NSObject+SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5CF13B96AAA0069C39F /* NSObject+SBJSON.m */; settings = {COMPILER_FLAGS = "-w"; }; }; - D32BC5E213B96AAA0069C39F /* NSString+SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D113B96AAA0069C39F /* NSString+SBJSON.m */; settings = {COMPILER_FLAGS = "-w"; }; }; - D32BC5E313B96AAA0069C39F /* SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D313B96AAA0069C39F /* SBJSON.m */; settings = {COMPILER_FLAGS = "-w"; }; }; - D32BC5E413B96AAA0069C39F /* SBJsonBase.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D513B96AAA0069C39F /* SBJsonBase.m */; settings = {COMPILER_FLAGS = "-w"; }; }; - D32BC5E513B96AAA0069C39F /* SBJsonParser.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D713B96AAA0069C39F /* SBJsonParser.m */; settings = {COMPILER_FLAGS = "-w"; }; }; - D32BC5E613B96AAA0069C39F /* SBJsonWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D913B96AAA0069C39F /* SBJsonWriter.m */; settings = {COMPILER_FLAGS = "-w"; }; }; + D32BC5DE13B96AAA0069C39F /* FBDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5C713B96AAA0069C39F /* FBDialog.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; + D32BC5DF13B96AAA0069C39F /* FBLoginDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5C913B96AAA0069C39F /* FBLoginDialog.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; + D32BC5E013B96AAA0069C39F /* FBRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5CB13B96AAA0069C39F /* FBRequest.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; + D32BC5E113B96AAA0069C39F /* NSObject+SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5CF13B96AAA0069C39F /* NSObject+SBJSON.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; + D32BC5E213B96AAA0069C39F /* NSString+SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D113B96AAA0069C39F /* NSString+SBJSON.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; + D32BC5E313B96AAA0069C39F /* SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D313B96AAA0069C39F /* SBJSON.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; + D32BC5E413B96AAA0069C39F /* SBJsonBase.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D513B96AAA0069C39F /* SBJsonBase.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; + D32BC5E513B96AAA0069C39F /* SBJsonParser.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D713B96AAA0069C39F /* SBJsonParser.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; + D32BC5E613B96AAA0069C39F /* SBJsonWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = D32BC5D913B96AAA0069C39F /* SBJsonWriter.m */; settings = {COMPILER_FLAGS = "-w -fno-objc-arc"; }; }; EA46D9B917EE4237001E32DC /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = EA46D9B817EE4237001E32DC /* Default-568h@2x.png */; }; /* End PBXBuildFile section */ @@ -370,6 +370,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -385,6 +386,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "FacebookLikeViewDemo/FacebookLikeViewDemo-Prefix.pch"; diff --git a/FacebookLikeViewDemo/FacebookLikeViewDemoAppDelegate.m b/FacebookLikeViewDemo/FacebookLikeViewDemoAppDelegate.m index 289ed96..ca8389a 100644 --- a/FacebookLikeViewDemo/FacebookLikeViewDemoAppDelegate.m +++ b/FacebookLikeViewDemo/FacebookLikeViewDemoAppDelegate.m @@ -13,7 +13,7 @@ @interface FacebookLikeViewDemoAppDelegate () -@property (nonatomic, retain) IBOutlet FacebookLikeViewDemoViewController *viewController; +@property (nonatomic, strong) IBOutlet FacebookLikeViewDemoViewController *viewController; @end @@ -45,11 +45,5 @@ - (void)applicationDidEnterBackground:(UIApplication *)application { forKey:SavedHTTPCookiesKey]; } -- (void)dealloc -{ - [_window release]; - [_viewController release]; - [super dealloc]; -} @end diff --git a/FacebookLikeViewDemo/FacebookLikeViewDemoViewController.m b/FacebookLikeViewDemo/FacebookLikeViewDemoViewController.m index 79ab293..11eb172 100644 --- a/FacebookLikeViewDemo/FacebookLikeViewDemoViewController.m +++ b/FacebookLikeViewDemo/FacebookLikeViewDemoViewController.m @@ -12,8 +12,8 @@ @interface FacebookLikeViewDemoViewController () -@property (readonly) Facebook *facebook; -@property (nonatomic, retain) IBOutlet FacebookLikeView *facebookLikeView; +@property (nonatomic, strong) Facebook *facebook; +@property (nonatomic, strong) IBOutlet FacebookLikeView *facebookLikeView; @end @@ -21,17 +21,11 @@ @implementation FacebookLikeViewDemoViewController - (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { - _facebook = [[Facebook alloc] initWithAppId:@"158575400878173" andDelegate:self]; + self.facebook = [[Facebook alloc] initWithAppId:@"158575400878173" andDelegate:self]; } return self; } -- (void)dealloc -{ - [_facebook release]; - [_facebookLikeView release]; - [super dealloc]; -} #pragma mark FBSessionDelegate @@ -59,20 +53,20 @@ - (void)facebookLikeViewDidRender:(FacebookLikeView *)aFacebookLikeView { } - (void)facebookLikeViewDidLike:(FacebookLikeView *)aFacebookLikeView { - UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Liked" + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Liked" message:@"You liked Yardsellr. Thanks!" delegate:self cancelButtonTitle:@"OK" - otherButtonTitles:nil] autorelease]; + otherButtonTitles:nil]; [alert show]; } - (void)facebookLikeViewDidUnlike:(FacebookLikeView *)aFacebookLikeView { - UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Unliked" + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unliked" message:@"You unliked Yardsellr. Where's the love?" delegate:self cancelButtonTitle:@"OK" - otherButtonTitles:nil] autorelease]; + otherButtonTitles:nil]; [alert show]; } diff --git a/FacebookLikeViewDemo/main.m b/FacebookLikeViewDemo/main.m index 52a489c..2736b93 100644 --- a/FacebookLikeViewDemo/main.m +++ b/FacebookLikeViewDemo/main.m @@ -10,8 +10,8 @@ int main(int argc, char *argv[]) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - int retVal = UIApplicationMain(argc, argv, nil, nil); - [pool release]; - return retVal; + @autoreleasepool { + int retVal = UIApplicationMain(argc, argv, nil, nil); + return retVal; + } }