NSDictionary(GCKAdditions) 类别
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
一个类别,向 NSDictionary 添加了一些便捷方法,用于安全地查找各种类型的值。
这些方法对于获取和设置 JSON 数据对象的字段特别有用。
- (nullable NSString *) gck_stringForKey: |
|
(NSString *) |
key |
withDefaultValue: |
|
(nullable NSString *) |
defaultValue |
|
|
| |
查找具有指定后备值的键的 NSString 值。
- Parameters
-
key | The key. |
defaultValue | The default value to return if the key is not found or if its value is not an NSString. |
- 返回
- 键的值(如果找到了键,且为 NSString);否则为默认值。
- (nullable NSString *) gck_stringForKey: |
|
(NSString *) |
key |
|
- (NSInteger) gck_integerForKey: |
|
(NSString *) |
key |
withDefaultValue: |
|
(NSInteger) |
defaultValue |
|
|
| |
查找具有指定后备值的键的 NSInteger 值。
- Parameters
-
key | The key. |
defaultValue | The default value to return if the key is not found or if its value is not an NSNumber. |
- 返回
- 如果找到了键的值,则为 NSNumber;否则为默认值。
- (NSUInteger) gck_uintegerForKey: |
|
(NSString *) |
key |
withDefaultValue: |
|
(NSUInteger) |
defaultValue |
|
|
| |
查找具有指定后备值的键的 NSUInteger 值。
- Parameters
-
key | The key. |
defaultValue | The default value to return if the key is not found or if its value is not an NSNumber. |
- 返回
- 如果找到了键的值,则为 NSNumber;否则为默认值。
- (NSInteger) gck_integerForKey: |
|
(NSString *) |
key |
|
- (NSUInteger) gck_uintegerForKey: |
|
(NSString *) |
key |
|
- (double) gck_doubleForKey: |
|
(NSString *) |
key |
withDefaultValue: |
|
(double) |
defaultValue |
|
|
| |
查找具有指定后备值的键的 double 值。
- Parameters
-
key | The key. |
defaultValue | The default value to return if the key is not found or if its value is not an NSNumber. |
- 返回
- 如果找到了键的值,则为 NSNumber;否则为默认值。
- (double) gck_doubleForKey: |
|
(NSString *) |
key |
|
查找回退值为 0.0
的键的 double 值。
- Parameters
-
- 返回
- 键的值(如果找到了键,且为 NSNumber);否则为
0.0
。
- (BOOL) gck_boolForKey: |
|
(NSString *) |
key |
withDefaultValue: |
|
(BOOL) |
defaultValue |
|
|
| |
查找具有指定后备值的键的 BOOL 值。
- Parameters
-
key | The key. |
defaultValue | The default value to return if the key is not found or if its value is not an NSNumber. |
- 返回
- 如果找到了键的值,则为 NSNumber;否则为默认值。
- (BOOL) gck_boolForKey: |
|
(NSString *) |
key |
|
查找回退值为 NO
的键的 BOOL 值。
- Parameters
-
- 返回
- 键的值(如果找到了键,且为 NSNumber);否则为
NO
。
- (nullable NSDictionary *) gck_dictionaryForKey: |
|
(NSString *) |
key |
|
- (nullable NSArray *) gck_arrayForKey: |
|
(NSString *) |
key |
|
查找回退值为 nil
的键的 NSArray 值。
- Parameters
-
- 返回
- 键的值(如果找到了键,且为 NSArray),否则为
nil
。
- (nullable NSURL *) gck_urlForKey: |
|
(NSString *) |
key |
|
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-12-01。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2023-12-01。"],[[["This category adds convenient methods to NSDictionary for safely retrieving values of various types, especially for JSON data."],["It provides type-safe accessors for common types like NSString, NSInteger, NSUInteger, double, BOOL, NSDictionary, NSArray, and NSURL."],["Each accessor method looks up a value for a given key and returns the value if it's of the expected type, otherwise a default value is returned."],["Default values can be explicitly provided or are set to sensible defaults like nil, 0, or NO depending on the type."],["This category simplifies working with dictionaries, improves type safety, and reduces the risk of runtime errors when accessing potentially missing or mismatched values."]]],[]]