commit | author | age
|
2e29a3
|
1 |
/* |
L |
2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* This source code is licensed under the license found in the |
|
6 |
* LICENSE file in the root directory of this source tree. |
|
7 |
*/ |
|
8 |
|
|
9 |
#import <Foundation/Foundation.h> |
|
10 |
|
|
11 |
NS_ASSUME_NONNULL_BEGIN |
|
12 |
/** |
|
13 |
The purpose of this class is to serve as thin, type-safe wrapper |
|
14 |
around FBSDKTypeUtility |
|
15 |
*/ |
|
16 |
@interface FBSDKJSONField : NSObject |
|
17 |
|
|
18 |
/** |
|
19 |
This can only be created by FBSDKJSONValue. |
|
20 |
*/ |
|
21 |
- (instancetype)init NS_UNAVAILABLE; |
|
22 |
+ (instancetype)new NS_UNAVAILABLE; |
|
23 |
|
|
24 |
/** |
|
25 |
A safe method to unpack the values in the top-level JSON object. |
|
26 |
https://developer.apple.com/documentation/foundation/nsjsonserialization |
|
27 |
*/ |
|
28 |
- (void)matchArray:(void (^_Nullable)(NSArray<FBSDKJSONField *> *_Nonnull))arrayMatcher |
|
29 |
dictionary:(void (^_Nullable)(NSDictionary<NSString *, FBSDKJSONField *> *_Nonnull))dictionaryMatcher |
|
30 |
string:(void (^_Nullable)(NSString *_Nonnull))stringMatcher |
|
31 |
number:(void (^_Nullable)(NSNumber *_Nonnull))numberMatcher |
|
32 |
null:(void (^_Nullable)(void))nullMatcher; |
|
33 |
|
|
34 |
/** |
|
35 |
The underlying JSON object. The only guarantee we provide with this |
|
36 |
is that it passes [FBSDKTypeUtility isValidJSONObject:] |
|
37 |
*/ |
|
38 |
@property (nonnull, nonatomic, readonly, strong) id rawObject; |
|
39 |
|
|
40 |
- (NSArray<FBSDKJSONField *> *_Nullable)arrayOrNil; |
|
41 |
- (NSDictionary<NSString *, FBSDKJSONField *> *_Nullable)dictionaryOrNil; |
|
42 |
- (NSString *_Nullable)stringOrNil; |
|
43 |
- (NSNumber *_Nullable)numberOrNil; |
|
44 |
- (NSNull *_Nullable)nullOrNil; |
|
45 |
|
|
46 |
@end |
|
47 |
|
|
48 |
/** |
|
49 |
Represents Top-level JSON objects. |
|
50 |
*/ |
|
51 |
@interface FBSDKJSONValue : NSObject |
|
52 |
|
|
53 |
/** |
|
54 |
If the object does not pass [FBSDKTypeUtility isValidJSONObject:] |
|
55 |
this will return nil. |
|
56 |
*/ |
|
57 |
- (_Nullable instancetype)initWithPotentialJSONObject:(id)obj; |
|
58 |
|
|
59 |
- (instancetype)init NS_UNAVAILABLE; |
|
60 |
+ (instancetype)new NS_UNAVAILABLE; |
|
61 |
|
|
62 |
/** |
|
63 |
The underlying JSON object. The only guarantee we provide with this |
|
64 |
is that it passes [FBSDKTypeUtility isValidJSONObject:] |
|
65 |
*/ |
|
66 |
@property (nonatomic, readonly, strong) id rawObject; |
|
67 |
|
|
68 |
/** |
|
69 |
A safe method to unpack the values in the top-level JSON object. |
|
70 |
|
|
71 |
The specs are per Apple's documentation: https://developer.apple.com/documentation/foundation/nsjsonserialization |
|
72 |
*/ |
|
73 |
- (void)matchArray:(void (^_Nullable)(NSArray<FBSDKJSONField *> *))arrayMatcher |
|
74 |
dictionary:(void (^_Nullable)(NSDictionary<NSString *, FBSDKJSONField *> *))dictMatcher; |
|
75 |
|
|
76 |
/** |
|
77 |
Returns the dictionary if that's truly what it is, otherwise, nil. |
|
78 |
*/ |
|
79 |
- (NSDictionary<NSString *, FBSDKJSONField *> *_Nullable)matchDictionaryOrNil; |
|
80 |
|
|
81 |
/** |
|
82 |
The unsafe variant which drops all the type-safety for this class. |
|
83 |
If this object is nonnull, you at least have guarantees from Apple that this is NSNull, NSString, NSNumber, NSArray, or NSDictionary. |
|
84 |
*/ |
|
85 |
- (NSDictionary<NSString *, id> *_Nullable)unsafe_matchDictionaryOrNil; |
|
86 |
|
|
87 |
- (NSArray<FBSDKJSONField *> *_Nullable)matchArrayOrNil; |
|
88 |
- (NSArray *_Nullable)unsafe_matchArrayOrNil; |
|
89 |
|
|
90 |
@end |
|
91 |
|
|
92 |
/** |
|
93 |
FBSDKTypeUtility returns id, which is problematic in our codebase. |
|
94 |
|
|
95 |
You can wrap resulting objects in this to force users of your JSON to use |
|
96 |
type-safe bindings. |
|
97 |
|
|
98 |
If this is not a valid JSON object...this will return nil. |
|
99 |
*/ |
|
100 |
FBSDKJSONValue *_Nullable FBSDKCreateJSONFromString(NSString *_Nullable string, NSError *__autoreleasing *errorRef); |
|
101 |
|
|
102 |
NS_ASSUME_NONNULL_END |