Name | Type | iOS | tvOS | watchOS | macOS |
---|---|---|---|---|---|
has(key: Key) |
Method | 8+ | 9+ | 3+ | 10.10+ |
jsonData(prettify: Bool) |
Method | 8+ | 9+ | 3+ | 10.10+ |
jsonString(prettify: Bool) |
Method | 8+ | 9+ | 3+ | 10.10+ |
lowercaseAllKeys() |
Mutating Method | 8+ | 9+ | 3+ | 10.10+ |
Check if key exists in dictionary.
- type: Method.
- return type: Bool
- parameters:
- key: key to search for.
- returns: true if key exists in dictionary.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
let dict: [String : Any] = ["testKey": "testValue", "testArrayKey": [1, 2, 3, 4, 5]]
dict.has(key: "testKey") -> true
dict.has(key: "anotherKey") -> false
JSON Data from dictionary.
- type: Method.
- return type: Data?
- parameters:
- prettify: set true to prettify data (default is false).
- returns: optional JSON Data (if applicable).
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
JSON Data from dictionary.
- type: Method.
- return type: String?
- parameters:
- prettify: set true to prettify string (default is false).
- returns: optional JSON String (if applicable).
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
dict.jsonString() -> "{"testKey":"testValue","testArrayKey":[1,2,3,4,5]}"
dict.jsonString()
/*
returns the following string:
"{
"testKey" : "testValue",
"testArrayKey" : [
1,
2,
3,
4,
5
]
}"
*/
Lowercase all keys in dictionary.
- type: Mutating Method.
- availability:
iOS 8+
tvOS 9+
watchOS 3+
macOS 10.10+
.
Example
var dict = ["tEstKeY": "value"]
dict.lowercaseAllKeys()
print(dict) // prints "["testkey": "value"]"