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 |
|
|
| |
針對具有指定備用值的鍵查詢雙精度的值。
- 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
。
- 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 |
|
查詢鍵的 BOOL 值,備用值為 NO
。
- Parameters
-
- 傳回
- 鍵的值 (如果有找到且為 NSNumber),否則為
NO
。
- (nullable NSDictionary *) gck_dictionaryForKey: |
|
(NSString *) |
key |
|
- (nullable NSArray *) gck_arrayForKey: |
|
(NSString *) |
key |
|
查詢鍵的 NSArray 值 (備用值為 nil
)。
- Parameters
-
- 傳回
- 索引鍵的值 (如果找到且是 NSArray),否則為
nil
。
- (nullable NSURL *) gck_urlForKey: |
|
(NSString *) |
key |
|
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間: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"]],["上次更新時間: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."]]],[]]