Skip to content

Commit

Permalink
Merge pull request #1 from bignerdranch/replaces-isa-with-object-get-…
Browse files Browse the repository at this point in the history
…class

replaces deprecated isa with object_getClass()
  • Loading branch information
jeremy-w committed Dec 19, 2013
2 parents c3437e2 + 25f3f7c commit b0c5a44
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 18 deletions.
4 changes: 3 additions & 1 deletion UIKit/Classes/UIAction.m
Expand Up @@ -28,15 +28,17 @@
*/

#import "UIAction.h"
#import <objc/runtime.h>

@implementation UIAction
@synthesize target=_target, action=_action;

- (BOOL)isEqual:(id)object
{
Class cls = object_getClass(self);
if (object == self) {
return YES;
} else if ([object isKindOfClass:[isa class]]) {
} else if ([object isKindOfClass:[cls class]]) {
return ([object target] == self.target && [object action] == self.action);
} else {
return NO;
Expand Down
4 changes: 3 additions & 1 deletion UIKit/Classes/UIFont.m
Expand Up @@ -29,6 +29,7 @@

#import "UIFont.h"
#import <Cocoa/Cocoa.h>
#import <objc/runtime.h>

static NSString *UIFontSystemFontName = nil;
static NSString *UIFontBoldSystemFontName = nil;
Expand Down Expand Up @@ -191,7 +192,8 @@ - (UIFont *)fontWithSize:(CGFloat)fontSize
{
CTFontRef newFont = CTFontCreateCopyWithAttributes(_font, fontSize, NULL, NULL);
if (newFont) {
UIFont *theFont = [isa _fontWithCTFont:newFont];
Class cls = object_getClass(self);
UIFont *theFont = [cls _fontWithCTFont:newFont];
CFRelease(newFont);
return theFont;
} else {
Expand Down
4 changes: 3 additions & 1 deletion UIKit/Classes/UILongPressGestureRecognizer.m
Expand Up @@ -31,6 +31,7 @@
#import "UIGestureRecognizerSubclass.h"
#import "UITouch+UIPrivate.h"
#import "UIEvent.h"
#import <objc/runtime.h>

static CGFloat DistanceBetweenTwoPoints(CGPoint A, CGPoint B)
{
Expand Down Expand Up @@ -83,7 +84,8 @@ - (void)_cancelWaiting
{
if (_waiting) {
_waiting = NO;
[isa cancelPreviousPerformRequestsWithTarget:self selector:@selector(_beginGesture) object:nil];
Class cls = object_getClass(self);
[cls cancelPreviousPerformRequestsWithTarget:self selector:@selector(_beginGesture) object:nil];
}
}

Expand Down
4 changes: 3 additions & 1 deletion UIKit/Classes/UIMenuController.m
Expand Up @@ -36,6 +36,7 @@
#import <AppKit/NSMenu.h>
#import <AppKit/NSMenuItem.h>
#import <AppKit/NSApplication.h>
#import <objc/runtime.h>

NSString *const UIMenuControllerWillShowMenuNotification = @"UIMenuControllerWillShowMenuNotification";
NSString *const UIMenuControllerDidShowMenuNotification = @"UIMenuControllerDidShowMenuNotification";
Expand Down Expand Up @@ -194,7 +195,8 @@ - (void)update
{
UIApplication *app = [UIApplication sharedApplication];
UIResponder *firstResponder = [app.keyWindow _firstResponder];
NSArray *allItems = [[isa _defaultMenuItems] arrayByAddingObjectsFromArray:_menuItems];
Class cls = object_getClass(self);
NSArray *allItems = [[cls _defaultMenuItems] arrayByAddingObjectsFromArray:_menuItems];

[_enabledMenuItems removeAllObjects];

Expand Down
10 changes: 6 additions & 4 deletions UIKit/Classes/UINavigationBar.m
Expand Up @@ -38,6 +38,7 @@
#import "UIImage+UIPrivate.h"
#import "UIBarButtonItem.h"
#import "UIButton.h"
#import <objc/runtime.h>

static const UIEdgeInsets kButtonEdgeInsets = {0,0,0,0};
static const CGFloat kMinButtonWidth = 30;
Expand Down Expand Up @@ -199,11 +200,12 @@ - (void)_setViewsWithTransition:(_UINavigationBarTransition)transition animated:

CGRect leftFrame = CGRectZero;
CGRect rightFrame = CGRectZero;


Class cls = object_getClass(self);
if (backItem) {
_leftView = [isa _backButtonWithBarButtonItem:backItem.backBarButtonItem];
_leftView = [cls _backButtonWithBarButtonItem:backItem.backBarButtonItem];
} else {
_leftView = [isa _viewWithBarButtonItem:topItem.leftBarButtonItem];
_leftView = [cls _viewWithBarButtonItem:topItem.leftBarButtonItem];
}

if (_leftView) {
Expand All @@ -213,7 +215,7 @@ - (void)_setViewsWithTransition:(_UINavigationBarTransition)transition animated:
[self addSubview:_leftView];
}

_rightView = [isa _viewWithBarButtonItem:topItem.rightBarButtonItem];
_rightView = [cls _viewWithBarButtonItem:topItem.rightBarButtonItem];

if (_rightView) {
_rightView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
Expand Down
8 changes: 5 additions & 3 deletions UIKit/Classes/UINavigationItem.m
Expand Up @@ -32,6 +32,7 @@
#import "UINavigationItem+UIPrivate.h"
#import "UINavigationBar.h"
#import "UINavigationBar+UIPrivate.h"
#import <objc/runtime.h>

static void * const UINavigationItemContext = "UINavigationItemContext";

Expand Down Expand Up @@ -87,16 +88,17 @@ - (void)_setNavigationBar:(UINavigationBar *)navigationBar
// weak reference
if (_navigationBar == navigationBar)
return;


Class cls = object_getClass(self);
if (_navigationBar != nil && navigationBar == nil) {
// remove observation
for (NSString * keyPath in [isa _keyPathsTriggeringUIUpdates]) {
for (NSString * keyPath in [cls _keyPathsTriggeringUIUpdates]) {
[self removeObserver:self forKeyPath:keyPath];
}
}
else if (navigationBar != nil) {
// observe property changes to notify UI element
for (NSString * keyPath in [isa _keyPathsTriggeringUIUpdates]) {
for (NSString * keyPath in [cls _keyPathsTriggeringUIUpdates]) {
[self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:UINavigationItemContext];
}
}
Expand Down
11 changes: 7 additions & 4 deletions UIKit/Classes/UIPopoverView.m
Expand Up @@ -31,6 +31,7 @@
#import "UIImageView.h"
#import "UIImage+UIPrivate.h"
#import <QuartzCore/QuartzCore.h>
#import <objc/runtime.h>

typedef struct {
CGPoint from;
Expand Down Expand Up @@ -163,9 +164,10 @@ - (void)layoutSubviews
{
[super layoutSubviews];

const CGRect bounds = self.bounds;
_backgroundView.frame = [isa backgroundRectForBounds:bounds];
_contentContainerView.frame = [isa contentRectForBounds:bounds withNavigationBar:NO];
const CGRect bounds = self.bounds;
Class cls = object_getClass(self);
_backgroundView.frame = [cls backgroundRectForBounds:bounds];
_contentContainerView.frame = [cls contentRectForBounds:bounds withNavigationBar:NO];
_contentView.frame = _contentContainerView.bounds;
}

Expand Down Expand Up @@ -312,7 +314,8 @@ - (void)setContentView:(UIView *)aView
- (void)setContentSize:(CGSize)aSize animated:(BOOL)animated
{
CGRect frame = self.frame;
frame.size = [isa frameSizeForContentSize:aSize withNavigationBar:NO];
Class cls = object_getClass(self);
frame.size = [cls frameSizeForContentSize:aSize withNavigationBar:NO];

[UIView animateWithDuration:animated? 0.2 : 0
animations:^(void) {
Expand Down
4 changes: 3 additions & 1 deletion UIKit/Classes/UIResponder.m
Expand Up @@ -30,6 +30,7 @@
#import "UIResponder.h"
#import "UIWindow+UIPrivate.h"
#import "UIInputController.h"
#import <objc/runtime.h>

@implementation UIResponder

Expand Down Expand Up @@ -114,7 +115,8 @@ - (BOOL)resignFirstResponder

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if ([isa instancesRespondToSelector:action]) {
Class cls = object_getClass(self);
if ([cls instancesRespondToSelector:action]) {
return YES;
} else {
return [[self nextResponder] canPerformAction:action withSender:sender];
Expand Down
6 changes: 4 additions & 2 deletions UIKit/Classes/UIView.m
Expand Up @@ -42,6 +42,7 @@
#import "UIColor+UIPrivate.h"
#import "UIColorRep.h"
#import <QuartzCore/CALayer.h>
#import <objc/runtime.h>

NSString *const UIViewFrameDidChangeNotification = @"UIViewFrameDidChangeNotification";
NSString *const UIViewBoundsDidChangeNotification = @"UIViewBoundsDidChangeNotification";
Expand Down Expand Up @@ -81,14 +82,15 @@ - (id)init
- (id)initWithFrame:(CGRect)theFrame
{
if ((self=[super init])) {
_implementsDrawRect = [isa _instanceImplementsDrawRect];
Class cls = object_getClass(self);
_implementsDrawRect = [cls _instanceImplementsDrawRect];
_clearsContextBeforeDrawing = YES;
_autoresizesSubviews = YES;
_userInteractionEnabled = YES;
_subviews = [[NSMutableSet alloc] init];
_gestureRecognizers = [[NSMutableSet alloc] init];

_layer = [[[isa layerClass] alloc] init];
_layer = [[[cls layerClass] alloc] init];
_layer.delegate = self;
_layer.layoutManager = [UIViewLayoutManager layoutManager];

Expand Down

0 comments on commit b0c5a44

Please sign in to comment.