Skip to content

Instantly share code, notes, and snippets.

View karolkozub's full-sized avatar

Karol Kozub karolkozub

View GitHub Profile
@karolkozub
karolkozub / protocol-conformation-experiments
Last active August 29, 2015 14:22
Classes don't conform to protocols adopted through categories without matching implementations
#import <Foundation/Foundation.h>
@protocol ProtocolOne <NSObject>
@optional
- (void)one;
@end
@protocol ProtocolTwo <NSObject>
@optional
- (void)two;
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
@interface A : NSObject - (void)abc; @end
@interface B : A @end
@interface C : B @end
@implementation A - (void)abc { NSLog(@"-[A abc]"); } @end
@implementation B - (void)abc { NSLog(@"-[B abc]"); } @end
@implementation C - (void)abc { NSLog(@"-[C abc]"); }
-(void)abc_A { struct objc_super sup = {self, [A class]}; objc_msgSendSuper(&sup, @selector(abc)); }
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface NSInvocation (PrivateAPI) -(void)invokeUsingIMP:(IMP)imp; @end
@interface A : NSObject - (void)abc; @end
@interface B : A @end
@interface C : B @end
@interface X : NSObject - (void)xyz; @end
@implementation A - (void)abc { NSLog(@"-[A abc]"); } @end
@implementation B @end
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface A : NSObject - (void)abc; @end
@interface B : A @end
@interface C : B @end
@implementation A - (void)abc { NSLog(@"-[A abc]"); } @end
@implementation B @end
@implementation C - (void)abc { [super abc]; NSLog(@"-[C abc]"); } @end
@interface X : NSObject - (void)xyz; @end
@karolkozub
karolkozub / gist:22627a1231613d4755ba
Last active August 29, 2015 14:01
A quick follow up on http://macoscope.com/blog/mvc-layer-interaction-architecture/ to clarify ModelManager usage.
// Since ModelManager is usually a simple facade for many other smaller managers, it can dispatch most method calls to its subcomponents based on which protocol includes the selector.
BOOL ProtocolIncludesSelector (Protocol *protocol, SEL selector)
{
struct objc_method_description methodDescription = protocol_getMethodDescription(protocol, selector, YES, YES);
return NULL != methodDescription.name;
}