NSDictionary+BUUtilities.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // NSMutableDictionary+Utilities.h
  3. // BUAdSDK
  4. //
  5. // Created by 李盛 on 2018/2/28.
  6. // Copyright © 2018年 bytedance. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. @interface NSDictionary (BU_Helper)
  11. #pragma mark - Safe Value Type From Key
  12. - (nullable NSString *)bu_stringForKey:(NSString *)key defaultValue:(nullable NSString *)defalutValue;
  13. - (BOOL)bu_boolForKey:(NSString *)key defaultValue:(BOOL)defalutValue;
  14. - (NSInteger)bu_integerForKey:(NSString *)key defaultValue:(NSInteger)defalutValue;
  15. - (long)bu_longForKey:(NSString *)key defaultValue:(long)defalutValue;
  16. - (long long)bu_longLongForKey:(NSString *)key defaultValue:(long long)defalutValue;
  17. - (NSTimeInterval)bu_timeIntervalForKey:(NSString *)key defaultValue:(NSTimeInterval)defalutValue;
  18. - (float)bu_floatForKey:(NSString *)key defaultValue:(float)defalutValue;
  19. - (nullable NSArray *)bu_arrayForKey:(NSString *)key defaultValue:(nullable NSArray *)defalutValue;
  20. - (nullable NSDictionary *)bu_dictionaryForKey:(NSString *)key defaultValue:(nullable NSDictionary *)defalutValue;
  21. @end
  22. @interface NSDictionary(BU_JSONValue)
  23. - (nullable NSString *)bu_JSONRepresentation:(NSError **)error;
  24. + (nullable NSDictionary *)bu_dictionaryWithJSONData:(nullable NSData *)inData error:(NSError **)outError;
  25. + (nullable NSDictionary *)bu_dictionaryWithJSONString:(NSString *)inJSON error:(NSError **)outError;
  26. - (void)bu_forEachWithBlock:(void(^)(id key, id value))block;
  27. @end
  28. @interface NSDictionary(BU_Formate)
  29. - (void)bu_parserWithKey:(NSString *)key stringValue:(NSString *_Nullable*_Nullable)stringValue dictValue:(NSDictionary *_Nullable*_Nullable)dictValue aryValue:(NSArray *_Nullable*_Nullable)aryValue;
  30. @end
  31. @interface NSMutableDictionary (BU_Helper)
  32. #pragma mark - Safe Set Object For Key
  33. - (void)bu_setObject:(nullable id)object forKey:(nullable id<NSCopying>)key;
  34. @end
  35. NS_ASSUME_NONNULL_END