mirror of
https://github.com/zhigang1992/facebook-ios-sdk.git
synced 2026-05-01 02:43:01 +08:00
Remove unused FBSDKJSONValue.h/m files from FBSDKCoreKit_Basics
Reviewed By: samodom Differential Revision: D33759926 fbshipit-source-id: aa53ffff84bf4cc5e9e6dbdfdad0c808def7fa7a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b4f6c4e8a7
commit
a73aead26e
@@ -1,222 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "FBSDKJSONValue.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "FBSDKBasicUtility.h"
|
||||
#import "FBSDKSafeCast.h"
|
||||
#import "FBSDKTypeUtility.h"
|
||||
|
||||
@interface FBSDKJSONField ()
|
||||
- (instancetype)initWithPotentialJSONField:(id)obj;
|
||||
@end
|
||||
|
||||
static NSArray<FBSDKJSONField *> *createArray(id obj)
|
||||
{
|
||||
NSArray *const original = _FBSDKCastToClassOrNilUnsafeInternal(obj, NSArray.class);
|
||||
if (!original) {
|
||||
return @[];
|
||||
}
|
||||
|
||||
NSMutableArray<FBSDKJSONField *> *const fields =
|
||||
[[NSMutableArray alloc] initWithCapacity:original.count];
|
||||
|
||||
for (id field in original) {
|
||||
FBSDKJSONField *const f = [[FBSDKJSONField alloc] initWithPotentialJSONField:field];
|
||||
if (f) {
|
||||
[fields addObject:f];
|
||||
}
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
static NSDictionary<NSString *, FBSDKJSONField *> *createDictionary(id obj)
|
||||
{
|
||||
NSDictionary<NSString *, id> *const original = _FBSDKCastToClassOrNilUnsafeInternal(obj, NSDictionary.class);
|
||||
if (!original) {
|
||||
return @{};
|
||||
}
|
||||
|
||||
NSMutableDictionary<NSString *, FBSDKJSONField *> *const fields =
|
||||
[[NSMutableDictionary alloc] initWithCapacity:original.count];
|
||||
|
||||
for (id key in original) {
|
||||
// This is just a sanity check. Apple should only give us string keys
|
||||
// anyway.
|
||||
if (![key respondsToSelector:@selector(isKindOfClass:)] || ![key isKindOfClass:NSString.class]) {
|
||||
continue;
|
||||
}
|
||||
NSString *const stringKey = (NSString *)key;
|
||||
|
||||
FBSDKJSONField *const typedField = [[FBSDKJSONField alloc] initWithPotentialJSONField:original[key]];
|
||||
if (typedField) {
|
||||
fields[stringKey] = typedField;
|
||||
}
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
@implementation FBSDKJSONValue
|
||||
|
||||
- (nullable instancetype)initWithPotentialJSONObject:(id)obj
|
||||
{
|
||||
// If this isn't a real JSON object, dump it.
|
||||
if (![FBSDKTypeUtility isValidJSONObject:obj]) {
|
||||
return nil;
|
||||
}
|
||||
_rawObject = obj;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)matchArray:(void (^)(NSArray<FBSDKJSONField *> *))arrayMatcher
|
||||
dictionary:(void (^)(NSDictionary<NSString *, FBSDKJSONField *> *))dictMatcher
|
||||
{
|
||||
if (arrayMatcher && [_rawObject isKindOfClass:NSArray.class]) {
|
||||
arrayMatcher(createArray(_rawObject));
|
||||
} else if (dictMatcher && [_rawObject isKindOfClass:[NSDictionary<NSString *, id> class]]) {
|
||||
dictMatcher(createDictionary(_rawObject));
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, FBSDKJSONField *> *_Nullable)matchDictionaryOrNil
|
||||
{
|
||||
__block NSDictionary<NSString *, FBSDKJSONField *> *result = nil;
|
||||
[self matchArray:nil dictionary:^(NSDictionary<NSString *, FBSDKJSONField *> *_Nonnull value) {
|
||||
result = value;
|
||||
}];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, id> *_Nullable)unsafe_matchDictionaryOrNil
|
||||
{
|
||||
return [_rawObject isKindOfClass:NSDictionary.class] ? _rawObject : nil;
|
||||
}
|
||||
|
||||
- (NSArray<FBSDKJSONField *> *_Nullable)matchArrayOrNil
|
||||
{
|
||||
__block NSArray<FBSDKJSONField *> *result = nil;
|
||||
[self matchArray:^(NSArray<FBSDKJSONField *> *_Nonnull value) {
|
||||
result = value;
|
||||
} dictionary:nil];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSArray *_Nullable)unsafe_matchArrayOrNil
|
||||
{
|
||||
__block BOOL isArray = NO;
|
||||
[self matchArray:^(NSArray<FBSDKJSONField *> *_Nonnull _) {
|
||||
isArray = YES;
|
||||
} dictionary:nil];
|
||||
|
||||
return [_rawObject isKindOfClass:NSArray.class] ? _rawObject : nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation FBSDKJSONField
|
||||
|
||||
- (nullable instancetype)initWithPotentialJSONField:(id)obj
|
||||
{
|
||||
// If this is nil, don't wrap it.
|
||||
if (obj == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Per Apple's Docs, these are the only types FBSDKTypeUtility can return.
|
||||
if (
|
||||
![obj isKindOfClass:NSString.class]
|
||||
&& ![obj isKindOfClass:NSNumber.class]
|
||||
&& ![obj isKindOfClass:NSNull.class]
|
||||
&& ![obj isKindOfClass:NSDictionary.class]
|
||||
&& ![obj isKindOfClass:NSArray.class]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if ((self = [super init])) {
|
||||
_rawObject = obj;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)matchArray:(void (^)(NSArray<FBSDKJSONField *> *))arrayMatcher
|
||||
dictionary:(void (^)(NSDictionary<NSString *, FBSDKJSONField *> *_Nonnull))dictionaryMatcher
|
||||
string:(void (^)(NSString *_Nonnull))stringMatcher
|
||||
number:(void (^)(NSNumber *_Nonnull))numberMatcher
|
||||
null:(void (^)(void))nullMatcher
|
||||
{
|
||||
if (nullMatcher && [_rawObject isKindOfClass:NSNull.class]) {
|
||||
nullMatcher();
|
||||
} else if (numberMatcher && [_rawObject isKindOfClass:NSNumber.class]) {
|
||||
numberMatcher(_rawObject);
|
||||
} else if (stringMatcher && [_rawObject isKindOfClass:NSString.class]) {
|
||||
stringMatcher(_rawObject);
|
||||
} else if (arrayMatcher && [_rawObject isKindOfClass:NSArray.class]) {
|
||||
arrayMatcher(createArray(_rawObject));
|
||||
} else if (dictionaryMatcher && [_rawObject isKindOfClass:NSDictionary.class]) {
|
||||
dictionaryMatcher(createDictionary(_rawObject));
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray<FBSDKJSONField *> *_Nullable)arrayOrNil
|
||||
{
|
||||
__block NSArray<FBSDKJSONField *> *result = nil;
|
||||
[self matchArray:^(NSArray<FBSDKJSONField *> *_Nonnull a) {
|
||||
result = [a copy];
|
||||
} dictionary:nil string:nil number:nil null:nil];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, FBSDKJSONField *> *_Nullable)dictionaryOrNil
|
||||
{
|
||||
__block NSDictionary<NSString *, FBSDKJSONField *> *result = nil;
|
||||
[self matchArray:nil dictionary:^(NSDictionary<NSString *, FBSDKJSONField *> *_Nonnull d) {
|
||||
result = [d copy];
|
||||
} string:nil number:nil null:nil];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSString *_Nullable)stringOrNil
|
||||
{
|
||||
__block NSString *result = nil;
|
||||
[self matchArray:nil dictionary:nil string:^(NSString *_Nonnull s) {
|
||||
result = [s copy];
|
||||
} number:nil null:nil];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSNumber *_Nullable)numberOrNil
|
||||
{
|
||||
__block NSNumber *result = nil;
|
||||
[self matchArray:nil dictionary:nil string:nil number:^(NSNumber *_Nonnull n) {
|
||||
result = n;
|
||||
} null:nil];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSNull *_Nullable)nullOrNil
|
||||
{
|
||||
__block NSNull *result = nil;
|
||||
[self matchArray:nil dictionary:nil string:nil number:nil null:^{
|
||||
result = [NSNull null];
|
||||
}];
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
FBSDKJSONValue *_Nullable FBSDKCreateJSONFromString(NSString *_Nullable string, NSError *__autoreleasing *errorRef)
|
||||
{
|
||||
return
|
||||
[[FBSDKJSONValue alloc] initWithPotentialJSONObject:[FBSDKBasicUtility objectForJSONString:string error:errorRef]];
|
||||
}
|
||||
@@ -15,7 +15,6 @@
|
||||
#import <FBSDKCoreKit_Basics/FBSDKFileDataExtracting.h>
|
||||
#import <FBSDKCoreKit_Basics/FBSDKFileManaging.h>
|
||||
#import <FBSDKCoreKit_Basics/FBSDKInfoDictionaryProviding.h>
|
||||
#import <FBSDKCoreKit_Basics/FBSDKJSONValue.h>
|
||||
#import <FBSDKCoreKit_Basics/FBSDKLibAnalyzer.h>
|
||||
#import <FBSDKCoreKit_Basics/FBSDKSafeCast.h>
|
||||
#import <FBSDKCoreKit_Basics/FBSDKSessionProviding.h>
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
/**
|
||||
The purpose of this class is to serve as thin, type-safe wrapper
|
||||
around FBSDKTypeUtility
|
||||
*/
|
||||
@interface FBSDKJSONField : NSObject
|
||||
|
||||
/**
|
||||
This can only be created by FBSDKJSONValue.
|
||||
*/
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
/**
|
||||
A safe method to unpack the values in the top-level JSON object.
|
||||
https://developer.apple.com/documentation/foundation/nsjsonserialization
|
||||
*/
|
||||
- (void)matchArray:(void (^_Nullable)(NSArray<FBSDKJSONField *> *_Nonnull))arrayMatcher
|
||||
dictionary:(void (^_Nullable)(NSDictionary<NSString *, FBSDKJSONField *> *_Nonnull))dictionaryMatcher
|
||||
string:(void (^_Nullable)(NSString *_Nonnull))stringMatcher
|
||||
number:(void (^_Nullable)(NSNumber *_Nonnull))numberMatcher
|
||||
null:(void (^_Nullable)(void))nullMatcher;
|
||||
|
||||
/**
|
||||
The underlying JSON object. The only guarantee we provide with this
|
||||
is that it passes [FBSDKTypeUtility isValidJSONObject:]
|
||||
*/
|
||||
@property (nonnull, nonatomic, readonly, strong) id rawObject;
|
||||
|
||||
- (NSArray<FBSDKJSONField *> *_Nullable)arrayOrNil;
|
||||
- (NSDictionary<NSString *, FBSDKJSONField *> *_Nullable)dictionaryOrNil;
|
||||
- (NSString *_Nullable)stringOrNil;
|
||||
- (NSNumber *_Nullable)numberOrNil;
|
||||
- (NSNull *_Nullable)nullOrNil;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
Represents Top-level JSON objects.
|
||||
*/
|
||||
@interface FBSDKJSONValue : NSObject
|
||||
|
||||
/**
|
||||
If the object does not pass [FBSDKTypeUtility isValidJSONObject:]
|
||||
this will return nil.
|
||||
*/
|
||||
- (_Nullable instancetype)initWithPotentialJSONObject:(id)obj;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
/**
|
||||
The underlying JSON object. The only guarantee we provide with this
|
||||
is that it passes [FBSDKTypeUtility isValidJSONObject:]
|
||||
*/
|
||||
@property (nonatomic, readonly, strong) id rawObject;
|
||||
|
||||
/**
|
||||
A safe method to unpack the values in the top-level JSON object.
|
||||
|
||||
The specs are per Apple's documentation: https://developer.apple.com/documentation/foundation/nsjsonserialization
|
||||
*/
|
||||
- (void)matchArray:(void (^_Nullable)(NSArray<FBSDKJSONField *> *))arrayMatcher
|
||||
dictionary:(void (^_Nullable)(NSDictionary<NSString *, FBSDKJSONField *> *))dictMatcher;
|
||||
|
||||
/**
|
||||
Returns the dictionary if that's truly what it is, otherwise, nil.
|
||||
*/
|
||||
- (NSDictionary<NSString *, FBSDKJSONField *> *_Nullable)matchDictionaryOrNil;
|
||||
|
||||
/**
|
||||
The unsafe variant which drops all the type-safety for this class.
|
||||
If this object is nonnull, you at least have guarantees from Apple that this is NSNull, NSString, NSNumber, NSArray, or NSDictionary.
|
||||
*/
|
||||
- (NSDictionary<NSString *, id> *_Nullable)unsafe_matchDictionaryOrNil;
|
||||
|
||||
- (NSArray<FBSDKJSONField *> *_Nullable)matchArrayOrNil;
|
||||
- (NSArray *_Nullable)unsafe_matchArrayOrNil;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
FBSDKTypeUtility returns id, which is problematic in our codebase.
|
||||
|
||||
You can wrap resulting objects in this to force users of your JSON to use
|
||||
type-safe bindings.
|
||||
|
||||
If this is not a valid JSON object...this will return nil.
|
||||
*/
|
||||
FBSDKJSONValue *_Nullable FBSDKCreateJSONFromString(NSString *_Nullable string, NSError *__autoreleasing *errorRef);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Reference in New Issue
Block a user