hank
2018-04-18 655e6650051a9c08675d15e05ac3b7d9be98e714
commit | author | age
655e66 1 /*
H 2  * Copyright (C) 2017 Twitter, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 /**
19  This header is private to the Twitter Core SDK and not exposed for public SDK consumption
20  */
a0a843 21
H 22 #import <TwitterCore/TWTRConstants.h>
23
24 #ifdef __OBJC__
25
26 #define TWTRParameterAssertSettingError(condition, errorPointer)                                                                                                                                                 \
27     NSParameterAssert((condition));                                                                                                                                                                              \
28     if (!(condition)) {                                                                                                                                                                                          \
29         NSLog(@"[TwitterKit] %@ Invalid parameter not satisfying: %s", NSStringFromSelector(_cmd), #condition);                                                                                                  \
30         if (errorPointer != NULL) {                                                                                                                                                                              \
31             *errorPointer = [NSError errorWithDomain:TWTRErrorDomain code:TWTRErrorCodeMissingParameter userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Missing parameter %s", #condition]}]; \
32         }                                                                                                                                                                                                        \
33     }
34
35 #define TWTRParameterAssertOrReturnValue(condition, returnValue)                                                \
36     NSParameterAssert((condition));                                                                             \
37     if (!(condition)) {                                                                                         \
38         NSLog(@"[TwitterKit] %@ Invalid parameter not satisfying: %s", NSStringFromSelector(_cmd), #condition); \
39         return returnValue;                                                                                     \
40     }
41
42 #define TWTRParameterAssertOrReturnNil(condition)                                                               \
43     NSParameterAssert((condition));                                                                             \
44     if (!(condition)) {                                                                                         \
45         NSLog(@"[TwitterKit] %@ Invalid parameter not satisfying: %s", NSStringFromSelector(_cmd), #condition); \
46         return nil;                                                                                             \
47     }
48
49 #define TWTRParameterAssertOrReturn(condition)                                                                  \
50     NSParameterAssert((condition));                                                                             \
51     if (!(condition)) {                                                                                         \
52         NSLog(@"[TwitterKit] %@ Invalid parameter not satisfying: %s", NSStringFromSelector(_cmd), #condition); \
53         return;                                                                                                 \
54     }
55
56 #define TWTRAssertMainThread()                                                                         \
57     if (![NSThread isMainThread]) {                                                                    \
58         [NSException raise:NSInternalInconsistencyException format:@"Need to be on the main thread."]; \
59         return;                                                                                        \
60     }
61
62 // Check a single argument, and call a completion block if it's missing
63 #define TWTRCheckArgumentWithCompletion(condition, completion)     \
64     TWTRParameterAssertOrReturn(completion);                       \
65     NSError *parameterError;                                       \
66     TWTRParameterAssertSettingError((condition), &parameterError); \
67     if (parameterError) {                                          \
68         completion(nil, nil, parameterError);                      \
69         return;                                                    \
70     }
71
72 #define TWTRCheckArgumentWithCompletion2(condition, completion)    \
73     TWTRParameterAssertOrReturn(completion);                       \
74     NSError *parameterError;                                       \
75     TWTRParameterAssertSettingError((condition), &parameterError); \
76     if (parameterError) {                                          \
77         completion(nil, parameterError);                           \
78         return;                                                    \
79     }
80
81 #endif