forked from jspahrsummers/libextobjc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEXTSelectorChecking.h
52 lines (44 loc) · 1.65 KB
/
EXTSelectorChecking.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
44
45
46
47
48
49
50
51
52
//
// EXTSelectorChecking.h
// extobjc
//
// Created by Justin Spahr-Summers on 26.06.12.
// Copyright (C) 2012 Justin Spahr-Summers.
// Released under the MIT license.
//
#import <Foundation/Foundation.h>
#import "metamacros.h"
/**
* \@checkselector verifies at compile-time that a selector can be invoked
* against the given TARGET. The checked selector is then returned as a SEL.
*
* The variadic arguments should be pieces of the selector, each ending with
* ':'. For example:
*
* @code
[myButton addTarget:self action:@checkselector(self, buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[otherButton addTarget:self action:@checkselector(self, buttonAction:, withEvent:) forControlEvents:UIControlEventTouchUpInside];
* @endcode
*
* For zero-argument selectors, use \@checkselector0 instead.
*
* @bug This macro currently does not work with selectors with variadic
* arguments.
*
* @bug This macro will not work if the method on TARGET designated by the
* selector must accept a struct or union argument.
*/
#define checkselector(TARGET, ...) \
(((void)(NO && ((void)[TARGET metamacro_foreach(ext_checkselector_message_iter,, __VA_ARGS__)], NO)), \
metamacro_foreach(ext_checkselector_selector_iter,, __VA_ARGS__))).ext_toSelector
#define checkselector0(TARGET, SELECTOR) \
(((void)(NO && ((void)[TARGET SELECTOR], NO)), \
# SELECTOR)).ext_toSelector
/*** implementation details follow ***/
#define ext_checkselector_message_iter(INDEX, SELPART) \
SELPART (0)
#define ext_checkselector_selector_iter(INDEX, SELPART) \
# SELPART
@interface NSString (EXTCheckedSelectorAdditions)
- (SEL)ext_toSelector;
@end