This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 461
/
EXTMixin.h
44 lines (41 loc) · 1.43 KB
/
EXTMixin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// EXTMixin.h
// extobjc
//
// Created by Justin Spahr-Summers on 2010-11-10.
// Copyright (C) 2012 Justin Spahr-Summers.
// Released under the MIT license.
//
#import <objc/runtime.h>
#import <stdlib.h>
#import "EXTRuntimeExtensions.h"
/**
* "Mixes in" the class and instance methods of \a CLASS into pre-existing class
* \a TARGET. Only the methods of \a CLASS itself, and not any superclasses, are mixed
* in. Any methods by the same name in \a TARGET are overwritten.
*
* This macro should be placed at file scope in an implementation file.
*
* @note The mixing in occurs only after all +load methods in the image have been
* executed.
*
* @warning Calls to \c super in mixed-in methods may invoke erratic behavior
* due to the nature of \c objc_msgSendSuper().
*/
#define EXTMixin(TARGET, CLASS) \
/*
* using the "constructor" function attribute, we can ensure that this
* function is executed only AFTER all the Objective-C runtime setup (i.e.,
* after all +load methods have been executed)
*/ \
__attribute__((constructor)) \
static void ext_ ## TARGET ## _ ## CLASS ## _mixin (void) { \
/*
* obtain the class to inject into, and the class from which to copy
* methods
*/ \
Class targetClass = objc_getClass(# TARGET); \
Class sourceClass = objc_getClass(# CLASS); \
\
ext_replaceMethodsFromClass(sourceClass, targetClass); \
}