1 | #import <Foundation/Foundation.h>
|
2 | #import <Stripe/Stripe.h>
|
3 |
|
4 | #define EX_ENUM_CONVERTER_DEF(rType) + (rType)rType:(id)json;
|
5 |
|
6 | @interface EXTPSConvert : NSObject
|
7 | + (NSString *)STPBankAccountHolderTypeToString:(STPBankAccountHolderType)type;
|
8 | + (NSString *)STPBankAccountStatusToString:(STPBankAccountStatus)status;
|
9 | + (STPBankAccountHolderType)holderType:(id)json;
|
10 | + (STPBankAccountStatus)statusType:(id)json;
|
11 | + (UIColor *)UIColor:(id)json;
|
12 | + (NSArray *)NSArray:(id)json;
|
13 | + (NSDictionary *)NSDictionary:(id)json;
|
14 | + (NSString *)NSString:(id)json;
|
15 | + (NSNumber *)NSNumber:(id)json;
|
16 | + (NSArray<NSString *> *)NSStringArray:(id)json;
|
17 | + (NSArray *)EXConvertArrayValue:(SEL) type value:(id) json;
|
18 | EX_ENUM_CONVERTER_DEF(UIKeyboardAppearance)
|
19 | @end
|
20 |
|
21 | #define EX_ENUM_CONVERTER(rType, map, defaultValue, getter) \
|
22 | + (rType)rType:(id)json \
|
23 | { \
|
24 | NSNumber *defaultVal = @(defaultValue); \
|
25 | NSDictionary *mapping = map; \
|
26 | if (!json) { \
|
27 | return (rType)defaultValue; \
|
28 | } \
|
29 | NSArray *allValues = mapping.allValues; \
|
30 | if ([allValues containsObject:json] || [json isEqual: defaultVal]) { \
|
31 | return (rType)[json getter]; \
|
32 | } \
|
33 | return (rType)defaultValue; \
|
34 | }
|
35 |
|
36 | #define EX_JSON_ARRAY_CONVERTER_NAMED(type, name) + (NSArray *)name##Array:(id)json { return json; }
|
37 | #define EX_JSON_ARRAY_CONVERTER(type) EX_JSON_ARRAY_CONVERTER_NAMED(type, type)
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | #define EX_ARRAY_CONVERTER_NAMED(type, name) \
|
44 | + (NSArray<type *> *)name##Array:(id)json EX_DYNAMIC \
|
45 | { \
|
46 | return EXConvertArrayValue(@selector(name:), json); \
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | #define EX_ARRAY_CONVERTER(type) EX_ARRAY_CONVERTER_NAMED(type, type)
|
55 |
|