QuerySerialization
public class QuerySerialization
Encodes and decodes query strings.
-
Creates a query string from a dictionary.
Note
The returned string does not contain the
?
prefix.Declaration
Swift
public static func queryString(fromDictionary dictionary: [String: String], urlEncode: Bool = true) -> String
Parameters
dictionary
The dictionary to encode.
urlEncode
A Boolean indicating whether to add URL escapes to the query string. Default:
true
Return Value
The dictionary encoded as a query string (
"foo=baz&a=b"
).
-
Decodes a query string.
Note
If the query string is not valid, an empty dictionary is returned.
Declaration
Swift
public static func decode(queryString: String, removePercentEncoding: Bool = true) -> [String: String]
Parameters
queryString
The query string to decode.
removePercentEncoding
A Boolean indicating whether to remove URL encoding. Default:
true
Return Value
The key-value pairs contained in the query string.