Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit de7151367540e49a28b7cf2f979c52fec701d9e6 @joshaber joshaber committed Aug 25, 2010
Showing with 400 additions and 0 deletions.
  1. +37 −0 JAViewController.h
  2. +82 −0 JAViewController.m
  3. +13 −0 NSObject+JAExtensions.h
  4. +28 −0 NSObject+JAExtensions.m
  5. +17 −0 NSView+JAExtensions.h
  6. +223 −0 NSView+JAExtensions.m
@@ -0,0 +1,37 @@
+//
+// JAViewController.h
+//
+// Created by Josh Abernathy on 8/17/10.
+// Copyright (c) 2010 Maybe Apps. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface JAViewController : NSViewController {
+
+}
+
++ (id)viewController;
+
+- (void)viewDidLoad;
+
+// Called when the view has a superview and window. This does not necessarily mean the view is visible.
+- (void)viewWillAppear;
+- (void)viewDidAppear;
+
+// Called when the view no longer has a superview or no longer has a window.
+- (void)viewWillDisappear;
+- (void)viewDidDisappear;
+
+- (void)viewWillMoveToSuperview:(NSView *)newSuperview;
+- (void)viewDidMoveToSuperview;
+- (void)viewWillBeRemovedFromSuperview;
+- (void)viewWasRemovedFromSuperview;
+
+- (void)viewWillMoveToWindow:(NSWindow *)newWindow;
+- (void)viewDidMoveToWindow;
+- (void)viewWillBeRemovedFromWindow;
+- (void)viewWasRemovedFromWindow;
+
+@end
@@ -0,0 +1,82 @@
+//
+// JAViewController.m
+//
+// Created by Josh Abernathy on 8/17/10.
+// Copyright (c) 2010 Maybe Apps. All rights reserved.
+//
+
+#import "JAViewController.h"
+#import "NSView+JAExtensions.h"
+
+
+@implementation JAViewController
+
++ (id)viewController {
+ return [[[self alloc] initWithNibName:NSStringFromClass([self class]) bundle:nil] autorelease];
+}
+
+- (void)loadView {
+ [super loadView];
+
+ [self viewDidLoad];
+}
+
+- (void)setView:(NSView *)view {
+ [super setView:view];
+
+ self.view.viewController = self;
+}
+
+- (void)viewDidLoad {
+
+}
+
+- (void)viewWillAppear {
+ [self.view setNeedsLayout];
+}
+
+- (void)viewDidAppear {
+
+}
+
+- (void)viewWillDisappear {
+
+}
+
+- (void)viewDidDisappear {
+
+}
+
+- (void)viewWillMoveToSuperview:(NSView *)newSuperview {
+
+}
+
+- (void)viewDidMoveToSuperview {
+
+}
+
+- (void)viewWillBeRemovedFromSuperview {
+
+}
+
+- (void)viewWasRemovedFromSuperview {
+
+}
+
+- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
+
+}
+
+- (void)viewDidMoveToWindow {
+
+}
+
+- (void)viewWillBeRemovedFromWindow {
+
+}
+
+- (void)viewWasRemovedFromWindow {
+
+}
+
+@end
@@ -0,0 +1,13 @@
+//
+// NSObject+JAExtensions.h
+//
+// Created by Josh Abernathy on 8/18/10.
+// Copyright (c) 2010 Maybe Apps. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSObject (JAExtensions)
++ (void)swapMethod:(SEL)originalSelector with:(SEL)newSelector;
+@end
@@ -0,0 +1,28 @@
+//
+// NSObject+JAExtensions.m
+//
+// Created by Josh Abernathy on 8/18/10.
+// Copyright (c) 2010 Maybe Apps. All rights reserved.
+//
+
+#import "NSObject+JAExtensions.h"
+#import <objc/runtime.h>
+
+
+@implementation NSObject (JAExtensions)
+
++ (void)swapMethod:(SEL)originalSelector with:(SEL)newSelector {
+ Method originalMethod = class_getInstanceMethod(self, originalSelector);
+ Method newMethod = class_getInstanceMethod(self, newSelector);
+ const char *originalTypeEncoding = method_getTypeEncoding(originalMethod);
+ const char *newTypeEncoding = method_getTypeEncoding(newMethod);
+ NSAssert2(!strcmp(originalTypeEncoding, newTypeEncoding), @"Method type encodings must be the same: %s vs. %s", originalTypeEncoding, newTypeEncoding);
+
+ if(class_addMethod(self, originalSelector, method_getImplementation(newMethod), newTypeEncoding)) {
+ class_replaceMethod(self, newSelector, method_getImplementation(originalMethod), originalTypeEncoding);
+ } else {
+ method_exchangeImplementations(originalMethod, newMethod);
+ }
+}
+
+@end
@@ -0,0 +1,17 @@
+//
+// NSView+JAExtensions.h
+//
+// Created by Josh Abernathy on 8/18/10.
+// Copyright (c) 2010 Maybe Apps. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSView (JAExtensions)
+- (void)layoutSubviews;
+- (void)layoutIfNeeded;
+- (void)setNeedsLayout;
+
+@property (nonatomic, assign) IBOutlet NSViewController *viewController;
+@end
Oops, something went wrong.

0 comments on commit de71513

Please sign in to comment.