Protocols
The following protocols are available globally.
-
A protocol for the Activity type.
See moreDeclaration
Swift
public protocol ActivityProtocol : Enrichable, OriginalRepresentable, Reactionable
-
A protocol with a reference to the original object of itself.
See moreDeclaration
Swift
public protocol OriginalRepresentable
-
Missable is using to wrap objects with enrichment, where they was deleted and dependencies lost the link.
See moreDeclaration
Swift
public protocol Missable : Decodable, Encodable
-
A collection object protocol.
This protocol describe basic properties. You can extend them with own type, but you have to implement
Encodable
andDecodable
protocols in a specific way:- the protocol properties present on the root level of the user structure,
- additinal properties should be encoded/decoded in the nested
data
container.
Here is an example of a JSON responce:
{ "id": "burger", "collection": "food", "foreign_id":"food:burger" "data": { "name": "Burger" }, "created_at": "2018-12-17T15:23:26.591179Z", "updated_at": "2018-12-17T15:23:26.591179Z", "duration":"0.45ms" }
You can extend our opened
CollectionObject
class for the default protocol properties.Example with custom properties:
See morefinal class Food: CollectionObject { private enum CodingKeys: String, CodingKey { case name } var name: String init(name: String, id: String? = nil) { self.name = name super.init(collectionName: "food", id: id) } required init(from decoder: Decoder) throws { let dataContainer = try decoder.container(keyedBy: DataCodingKeys.self) let container = try dataContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .data) name = try container.decode(String.self, forKey: .name) try super.init(from: decoder) } override func encode(to encoder: Encoder) throws { var dataContainer = encoder.container(keyedBy: DataCodingKeys.self) var container = dataContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .data) try container.encode(name, forKey: .name) try super.encode(to: encoder) } }
Declaration
Swift
public protocol CollectionObjectProtocol : Enrichable
-
Undocumented
See moreDeclaration
Swift
public protocol ISO8601DateFormatter
-
A reaction protocol.
See moreDeclaration
Swift
public protocol ReactionProtocol : Decodable, Encodable, Equatable
-
A reactionable protocol.
See moreDeclaration
Swift
public protocol Reactionable
-
A user protocol.
This protocol describe basic properties. You can extend them with own type, but you have to implement
Encodable
andDecodable
protocols in a specific way:- the protocol properties present on the root level of the user structure,
- additinal properties should be encoded/decoded in the nested
data
container.
Here is an example of a JSON responce:
{ "id": "alice123", "data": { "name": "Alice" }, "created_at": "2018-12-17T15:23:26.591179Z", "updated_at": "2018-12-17T15:23:26.591179Z", "duration":"0.45ms" }
You can extend our opened
User
class for the default protocol properties.Example with custom properties:
final class User: GetStream.User { private enum CodingKeys: String, CodingKey { case name } var name: String init(id: String, name: String) { self.name = name super.init(id: id) } required init(from decoder: Decoder) throws { let dataContainer = try decoder.container(keyedBy: DataCodingKeys.self) let container = try dataContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .data) name = try container.decode(String.self, forKey: .name) try super.init(from: decoder) } override func encode(to encoder: Encoder) throws { var dataContainer = encoder.container(keyedBy: DataCodingKeys.self) var container = dataContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .data) try container.encode(name, forKey: .name) try super.encode(to: encoder) } }
Here is an example how to use a custom User type:
See morelet user = User(id: "alice123", name: "Alice") client.create(user: user) { // Let's try retrieve details of the created user and use custom properties. client.get(typeOf: User.self, userId: "alice123") { let user = try? $0.get() // here the user is a custom User type. print(user?.name) // it will print "Alice". } }
Declaration
Swift
public protocol UserProtocol : Enrichable