MapEncodable
public protocol MapEncodable
A protocol that adds support of complex objects to be serialized into a JSON object.
-
Fill a map with the contents of this object.
Declaration
Swift
func fill(map: Map) throwsParameters
mapA map that needs to be filled with this object. In default implementations, this map is empty.
-
filledMap()Extension methodReturns a map filled with the contents of this object
Throws
Throws an error if this object fails to initalize. This will mostly likely throw aMapDecodingErrorbut since this method is implemented by the user, it may throw any error.Declaration
Swift
func filledMap() throws -> MapReturn Value
The filled map.
-
json()Extension methodReturns a map filled with the contents of this object
Throws
Throws an error if this object fails to initalize. This will mostly likely throw aMapDecodingErrorbut since this method is implemented by the user, it may throw any error.Declaration
Swift
func json() throws -> [String : Any?]Return Value
The filled map.
-
jsonData(options:)Extension methodSerializes this object into a JSON
DataobjectThrows
Throws an error if this object failed to serialize.Declaration
Swift
public func jsonData(options: JSONSerialization.WritingOptions = []) throws -> DataParameters
optionsThe writing options.
Return Value
The serialized object.
-
jsonString(options:encoding:)Extension methodSerializes this object into a JSON
StringThrows
Throws an error if this object failed to serialize.Declaration
Swift
public func jsonString(options: JSONSerialization.WritingOptions = [], encoding: String.Encoding = .utf8) throws -> String?Parameters
optionsThe writing options.
encodingThe string encoding that should be used.
Return Value
The serialized object.
View on GitHub
MapEncodable Protocol Reference