Revision: 4296
http://skim-app.svn.sourceforge.net/skim-app/?rev=4296&view=rev
Author: hofman
Date: 2008-07-24 18:49:48 +0000 (Thu, 24 Jul 2008)
Log Message:
-----------
add an intermediate function for method swizzle
Modified Paths:
--------------
trunk/NSObject_SKExtensions.m
Modified: trunk/NSObject_SKExtensions.m
===================================================================
--- trunk/NSObject_SKExtensions.m 2008-07-24 17:38:41 UTC (rev 4295)
+++ trunk/NSObject_SKExtensions.m 2008-07-24 18:49:48 UTC (rev 4296)
@@ -40,12 +40,10 @@
#import "SKRuntime.h"
[EMAIL PROTECTED] NSObject (SKExtensions)
-
static inline IMP SKReplaceMethodImplementation(Class aClass, SEL aSelector,
IMP anImp, const char *types, BOOL isInstance) {
IMP imp = NULL;
if (anImp) {
- Method method = isInstance ? class_getClassMethod(aClass, aSelector) :
class_getClassMethod(aClass, aSelector);
+ Method method = isInstance ? class_getInstanceMethod(aClass,
aSelector) : class_getClassMethod(aClass, aSelector);
if (method) {
imp = SK_method_getImplementation(method);
if (types == NULL)
@@ -57,6 +55,13 @@
return imp;
}
+static inline IMP SKReplaceMethodImplementationFromSelector(Class aClass, SEL
aSelector, SEL impSelector, BOOL isInstance) {
+ Method method = isInstance ? class_getInstanceMethod(aClass, impSelector)
: class_getClassMethod(aClass, impSelector);
+ return method ? SKReplaceMethodImplementation(aClass, aSelector,
SK_method_getImplementation(method), SK_method_getTypeEncoding(method),
isInstance) : NULL;
+}
+
[EMAIL PROTECTED] NSObject (SKExtensions)
+
+ (IMP)setMethod:(IMP)anImp typeEncoding:(const char *)types
forSelector:(SEL)aSelector {
return SKReplaceMethodImplementation(self, aSelector, anImp, types, NO);
}
@@ -70,8 +75,7 @@
}
+ (IMP)setMethodFromSelector:(SEL)impSelector forSelector:(SEL)aSelector {
- Method method = class_getClassMethod(self, impSelector);
- return method ? [self setMethod:SK_method_getImplementation(method)
typeEncoding:SK_method_getTypeEncoding(method) forSelector:aSelector] : NULL;
+ return SKReplaceMethodImplementationFromSelector(self, aSelector,
impSelector, NO);
}
- (IMP)setMethodFromSelector:(SEL)impSelector forSelector:(SEL)aSelector {
@@ -79,8 +83,7 @@
}
+ (IMP)setInstanceMethodFromSelector:(SEL)impSelector
forSelector:(SEL)aSelector {
- Method method = class_getInstanceMethod(self, impSelector);
- return method ? [self
setInstanceMethod:SK_method_getImplementation(method)
typeEncoding:SK_method_getTypeEncoding(method) forSelector:aSelector] : NULL;
+ return SKReplaceMethodImplementationFromSelector(self, aSelector,
impSelector, YES);
}
+ (void)exchangeMethodForSelector:(SEL)aSelector1
withMethodForSelector:(SEL)aSelector2 {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit