Skip to content

Commit

Permalink
Migrate to ARC.
Browse files Browse the repository at this point in the history
  • Loading branch information
samvermette committed Mar 4, 2012
1 parent 3044698 commit 171311f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 65 deletions.
6 changes: 0 additions & 6 deletions Demo/Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
#pragma mark -
#pragma mark Memory management

- (void)dealloc {
[window release];
[navigationController release];

[super dealloc];
}


@end
Expand Down
4 changes: 2 additions & 2 deletions Demo/Classes/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ @implementation ViewController

- (void)pushWebViewController {
NSURL *URL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki/Friday_(Rebecca_Black_song)"];
SVWebViewController *webViewController = [[[SVWebViewController alloc] initWithURL:URL] autorelease];
SVWebViewController *webViewController = [[SVWebViewController alloc] initWithURL:URL];
[self.navigationController pushViewController:webViewController animated:YES];
}


- (void)presentWebViewController {
NSURL *URL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki/Friday_(Rebecca_Black_song)"];
SVModalWebViewController *webViewController = [[[SVModalWebViewController alloc] initWithURL:URL] autorelease];
SVModalWebViewController *webViewController = [[SVModalWebViewController alloc] initWithURL:URL];
webViewController.modalPresentationStyle = UIModalPresentationPageSheet;
webViewController.availableActions = SVWebViewControllerAvailableActionsOpenInSafari | SVWebViewControllerAvailableActionsCopyLink | SVWebViewControllerAvailableActionsMailLink;
[self presentModalViewController:webViewController animated:YES];
Expand Down
4 changes: 4 additions & 0 deletions Demo/SVWeb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All @@ -247,6 +248,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = SVWeb_Prefix.pch;
Expand All @@ -269,6 +271,7 @@
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
SDKROOT = iphoneos;
};
name = Debug;
Expand All @@ -282,6 +285,7 @@
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
};
Expand Down
8 changes: 4 additions & 4 deletions Demo/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool drain];
return retVal;
@autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, nil);
return retVal;
}
}
10 changes: 4 additions & 6 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_IMPORTANT: on Oct 26th 2011, SVWebViewController received a major overhaul of its inner working. Upgrading from an earlier version of a SVWebViewController will crash your app if you're presenting SVWebViewController modally (using @presentModalViewController:@). Please update your code and use @SVModalWebViewController@ in replacement of @SVWebViewController@ when it's presented modally._
__Note: SVWebViewController now uses Automatic Reference Counting (ARC). Find the last MRC commit on the "master-mrc":https://github.com/samvermette/SVWebViewController/tree/master-mrc branch.__

h1. SVWebViewController

Expand Down Expand Up @@ -39,7 +39,9 @@ SVModalWebViewController *webViewController = [[SVModalWebViewController alloc]
[webViewController release];
</pre>

@SVModalWebViewController@ boasts a @barsTintColor@ property, if you're into giving the navigation bar and toolbar a custom tint color.
h3. Changing the bars tint color

Only @SVModalWebViewController@ supports custom tint colors using the @barsTintColor@ property.

h3. Customizing the action sheet

Expand All @@ -56,10 +58,6 @@ enum {

Default is @SVWebViewControllerAvailableActionsOpenInSafari | SVWebViewControllerAvailableActionsMailLink@.

h2. Automatic Referencing counting (ARC) support

Maintaining an official ARC branch has proven to be too much work, often leading to confusion since the ARC branch is always a few commits behind. If you'd like to use SVWebViewController in your ARC-enabled project, you'll have to "add the @-fno-objc-arc@ compiler flag":http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project to all of SVWebViewController's files.

h2. Credits

SVWebViewController is brought to you by "Sam Vermette":http://samvermette.com and "contributors to the project":https://github.com/samvermette/SVWebViewController/contributors. If you have feature suggestions or bug reports, feel free to help out by sending pull requests or by "creating new issues":https://github.com/samvermette/SVWebViewController/issues/new. If you're using SVWebViewController in your project, attribution would be nice.
6 changes: 4 additions & 2 deletions SVWebViewController/SVModalWebViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ enum {
SVWebViewControllerAvailableActionsMailLink = 1 << 1,
SVWebViewControllerAvailableActionsCopyLink = 1 << 2
};

typedef NSUInteger SVWebViewControllerAvailableActions;


@class SVWebViewController;

@interface SVModalWebViewController : UINavigationController

- (id)initWithAddress:(NSString*)urlString;
- (id)initWithURL:(NSURL *)URL;

@property (nonatomic, retain) UIColor *barsTintColor;
@property (nonatomic, assign) SVWebViewControllerAvailableActions availableActions;
@property (nonatomic, strong) UIColor *barsTintColor;
@property (nonatomic, readwrite) SVWebViewControllerAvailableActions availableActions;

@end
10 changes: 3 additions & 7 deletions SVWebViewController/SVModalWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@interface SVModalWebViewController ()

@property (nonatomic, assign) SVWebViewController *webViewController;
@property (nonatomic, strong) SVWebViewController *webViewController;

@end

Expand All @@ -22,19 +22,15 @@ @implementation SVModalWebViewController

#pragma mark - Initialization

- (void)dealloc {
self.barsTintColor = nil;
[super dealloc];
}

- (id)initWithAddress:(NSString*)urlString {
return [self initWithURL:[NSURL URLWithString:urlString]];
}

- (id)initWithURL:(NSURL *)URL {
self.webViewController = [[[SVWebViewController alloc] initWithURL:URL] autorelease];
self.webViewController = [[SVWebViewController alloc] initWithURL:URL];
if (self = [super initWithRootViewController:self.webViewController]) {
self.webViewController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:webViewController action:@selector(doneButtonClicked:)] autorelease];
self.webViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:webViewController action:@selector(doneButtonClicked:)];
}
return self;
}
Expand Down
4 changes: 2 additions & 2 deletions SVWebViewController/SVWebViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#import "SVModalWebViewController.h"

@interface SVWebViewController : UIViewController <UIWebViewDelegate, UIActionSheetDelegate, MFMailComposeViewControllerDelegate>
@interface SVWebViewController : UIViewController

- (id)initWithAddress:(NSString*)urlString;
- (id)initWithURL:(NSURL*)URL;

@property (nonatomic, assign) SVWebViewControllerAvailableActions availableActions;
@property (nonatomic, readwrite) SVWebViewControllerAvailableActions availableActions;

@end
57 changes: 21 additions & 36 deletions SVWebViewController/SVWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

#import "SVWebViewController.h"

@interface SVWebViewController ()
@interface SVWebViewController () <UIWebViewDelegate, UIActionSheetDelegate, MFMailComposeViewControllerDelegate>

@property (nonatomic, retain, readonly) UIBarButtonItem *backBarButtonItem;
@property (nonatomic, retain, readonly) UIBarButtonItem *forwardBarButtonItem;
@property (nonatomic, retain, readonly) UIBarButtonItem *refreshBarButtonItem;
@property (nonatomic, retain, readonly) UIBarButtonItem *stopBarButtonItem;
@property (nonatomic, retain, readonly) UIBarButtonItem *actionBarButtonItem;
@property (nonatomic, retain, readonly) UIActionSheet *pageActionSheet;
@property (nonatomic, strong, readonly) UIBarButtonItem *backBarButtonItem;
@property (nonatomic, strong, readonly) UIBarButtonItem *forwardBarButtonItem;
@property (nonatomic, strong, readonly) UIBarButtonItem *refreshBarButtonItem;
@property (nonatomic, strong, readonly) UIBarButtonItem *stopBarButtonItem;
@property (nonatomic, strong, readonly) UIBarButtonItem *actionBarButtonItem;
@property (nonatomic, strong, readonly) UIActionSheet *pageActionSheet;

@property (nonatomic, retain, readonly) UIWebView *mainWebView;
@property (nonatomic, retain) NSURL *URL;
@property (nonatomic, strong) UIWebView *mainWebView;
@property (nonatomic, strong) NSURL *URL;

- (id)initWithAddress:(NSString*)urlString;
- (id)initWithURL:(NSURL*)URL;
Expand Down Expand Up @@ -134,24 +134,12 @@ - (id)initWithURL:(NSURL*)pageURL {

- (void)dealloc {
mainWebView.delegate = nil;
[mainWebView release];

[URL release];
[backBarButtonItem release];
[forwardBarButtonItem release];
[refreshBarButtonItem release];
[stopBarButtonItem release];
[actionBarButtonItem release];

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

[super dealloc];
}

#pragma mark - View lifecycle

- (void)loadView {

mainWebView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
mainWebView.delegate = self;
mainWebView.scalesPageToFit = YES;
Expand All @@ -166,15 +154,13 @@ - (void)viewDidLoad {

- (void)viewDidUnload {
[super viewDidUnload];

[mainWebView release], mainWebView = nil;

[backBarButtonItem release], backBarButtonItem = nil;
[forwardBarButtonItem release], forwardBarButtonItem = nil;
[refreshBarButtonItem release], refreshBarButtonItem = nil;
[stopBarButtonItem release], stopBarButtonItem = nil;
[actionBarButtonItem release], actionBarButtonItem = nil;
[pageActionSheet release], pageActionSheet = nil;
mainWebView = nil;
backBarButtonItem = nil;
forwardBarButtonItem = nil;
refreshBarButtonItem = nil;
stopBarButtonItem = nil;
actionBarButtonItem = nil;
pageActionSheet = nil;
}

- (void)viewWillAppear:(BOOL)animated {
Expand Down Expand Up @@ -212,9 +198,9 @@ - (void)updateToolbarItems {

UIBarButtonItem *refreshStopBarButtonItem = self.mainWebView.isLoading ? self.stopBarButtonItem : self.refreshBarButtonItem;

UIBarButtonItem *fixedSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpace.width = 5.0f;
UIBarButtonItem *flexibleSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSArray *items;
Expand Down Expand Up @@ -245,9 +231,9 @@ - (void)updateToolbarItems {
nil];
}

UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, toolbarWidth, 44.0f)] autorelease];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, toolbarWidth, 44.0f)];
toolbar.items = items;
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
}

else {
Expand Down Expand Up @@ -333,7 +319,6 @@ - (void)actionButtonClicked:(id)sender {
else
[self.pageActionSheet showFromToolbar:self.navigationController.toolbar];

[pageActionSheet release];
}

- (void)doneButtonClicked:(id)sender {
Expand All @@ -356,7 +341,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger

else if([title isEqualToString:NSLocalizedString(@"Mail Link to this Page", @"")]) {

MFMailComposeViewController *mailViewController = [[[MFMailComposeViewController alloc] init] autorelease];
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];

mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:[self.mainWebView stringByEvaluatingJavaScriptFromString:@"document.title"]];
Expand Down

0 comments on commit 171311f

Please sign in to comment.