Skip to content

Commit

Permalink
Renamed methodForSelector: to instanceMethodForSelector:
Browse files Browse the repository at this point in the history
Also added methodForSelector: back which is for class methods.
  • Loading branch information
NSExceptional committed Aug 21, 2016
1 parent 7214616 commit 098af25
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions MirrorKit.podspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

Pod::Spec.new do |s|
s.name = "MirrorKit"
s.version = "1.0.1"
s.summary = "A library for refleciton in Objectice-C."
s.version = "1.1.0"
s.summary = "A library for reflection in Objectice-C."
s.homepage = "https://github.com/ThePantsThief/MirrorKit"
s.license = 'MIT'
s.author = { "ThePantsThief" => "tannerbennett@me.com" }
Expand Down
15 changes: 12 additions & 3 deletions Pod/Classes/MKMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ NS_ASSUME_NONNULL_BEGIN
@interface MKMethod : MKSimpleMethod

+ (instancetype)method:(Method)method;
/** Constructs an \c MKMethod for the given selector on the given class.

/** Constructs an \c MKMethod for the given instance method on the given class.
@return The newly constructed \c MKMethod object, or \c nil if \e if the specified class or its superclasses do not contain an instance method with the specified selector. */
+ (instancetype)methodForSelector:(SEL)selector class:(Class)cls;
/** Constructs an \c MKMethod for the given selector on the given class, only if the given
+ (instancetype)instanceMethodForSelector:(SEL)selector class:(Class)cls;
/** Constructs an \c MKMethod for the given instance method on the given class, only if the given
class itself defines or overrides the desired method.
@return The newly constructed \c MKMethod object, or \c nil \e if the specified class does not define or override, or if the specified class or its superclasses do not contain, an instance method with the specified selector. */
+ (instancetype)instanceMethodForSelector:(SEL)selector implementedInClass:(Class)cls;

/** Constructs an \c MKMethod for the given class method on the given class.
@return The newly constructed \c MKMethod object, or \c nil if \e if the specified class or its superclasses do not contain a class method with the specified selector. */
+ (instancetype)methodForSelector:(SEL)selector class:(Class)cls;
/** Constructs an \c MKMethod for the given class method on the given class, only if the given
class itself defines or overrides the desired method.
@return The newly constructed \c MKMethod object, or \c nil \e if the specified class does not define or override, or if the specified class or its superclasses do not contain, a class method with the specified selector. */
+ (instancetype)methodForSelector:(SEL)selector implementedInClass:(Class)cls;

@property (nonatomic, readonly) Method objc_method;
Expand Down
22 changes: 20 additions & 2 deletions Pod/Classes/MKMethod.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,34 @@ + (instancetype)method:(Method)method {
return [[self alloc] initWithMethod:method];
}

+ (instancetype)methodForSelector:(SEL)selector class:(Class)cls {
+ (instancetype)instanceMethodForSelector:(SEL)selector class:(Class)cls {
Method m = class_getInstanceMethod([cls class], selector);
if (m == NULL) return nil;
return [self method:m];
}

+ (instancetype)instanceMethodForSelector:(SEL)selector implementedInClass:(Class)cls {
if (![cls superclass]) { return [self instanceMethodForSelector:selector class:cls]; }

BOOL unique = [[cls class] instanceMethodForSelector:selector] != [[cls superclass] instanceMethodForSelector:selector];

if (unique) {
return [self instanceMethodForSelector:selector class:cls];
}

return nil;
}

+ (instancetype)methodForSelector:(SEL)selector class:(Class)cls {
Method m = class_getClassMethod([cls class], selector);
if (m == NULL) return nil;
return [self method:m];
}

+ (instancetype)methodForSelector:(SEL)selector implementedInClass:(Class)cls {
if (![cls superclass]) { return [self methodForSelector:selector class:cls]; }

BOOL unique = [[cls class] instanceMethodForSelector:selector] != [[cls superclass] instanceMethodForSelector:selector];
BOOL unique = [[cls class] methodForSelector:selector] != [[cls superclass] methodForSelector:selector];

if (unique) {
return [self methodForSelector:selector class:cls];
Expand Down

0 comments on commit 098af25

Please sign in to comment.