From 7b0bfcf8edb89f10e122de05fbb4422cd5309047 Mon Sep 17 00:00:00 2001 From: "yonguang.li" Date: Thu, 28 Dec 2017 17:03:07 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90ADD=E3=80=91static=20method=20supporte?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aspects.h | 5 +++++ Aspects.m | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/Aspects.h b/Aspects.h index 5508f86..3203f6f 100644 --- a/Aspects.h +++ b/Aspects.h @@ -59,6 +59,11 @@ typedef NS_OPTIONS(NSUInteger, AspectOptions) { usingBlock:(id)block error:(NSError **)error; ++ (id)aspect_hookClassSelector:(SEL)selector + withOptions:(AspectOptions)options + usingBlock:(id)block + error:(NSError **)error; + /// Adds a block of code before/instead/after the current `selector` for a specific instance. - (id)aspect_hookSelector:(SEL)selector withOptions:(AspectOptions)options diff --git a/Aspects.m b/Aspects.m index c907066..e2ec425 100644 --- a/Aspects.m +++ b/Aspects.m @@ -103,6 +103,14 @@ @implementation NSObject (Aspects) return aspect_add((id)self, selector, options, block, error); } ++ (id)aspect_hookClassSelector:(SEL)selector + withOptions:(AspectOptions)options + usingBlock:(id)block + error:(NSError **)error { + Class cls = object_getClass(self.class); + return [cls aspect_hookSelector:selector withOptions:options usingBlock:block error:error]; +} + /// @return A token which allows to later deregister the aspect. - (id)aspect_hookSelector:(SEL)selector withOptions:(AspectOptions)options