Protocols

The following protocols are available globally.

  • A protocol for the Activity type.

    See more

    Declaration

    Swift

    public protocol ActivityProtocol : Enrichable, OriginalRepresentable, Reactionable
  • A protocol with a reference to the original object of itself.

    See more

    Declaration

    Swift

    public protocol OriginalRepresentable
  • A protocol for enrichable objects.

    See more

    Declaration

    Swift

    public protocol Enrichable : Missable
  • Missable is using to wrap objects with enrichment, where they was deleted and dependencies lost the link.

    See more

    Declaration

    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 and Decodable 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:

        final 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)
            }
        }
    
    See more

    Declaration

    Swift

    public protocol CollectionObjectProtocol : Enrichable

ISO8601 Date Formatter

  • Undocumented

    See more

    Declaration

    Swift

    public protocol ISO8601DateFormatter
  • A reaction protocol.

    See more

    Declaration

    Swift

    public protocol ReactionProtocol : Decodable, Encodable, Equatable
  • A reactionable protocol.

    See more

    Declaration

    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 and Decodable 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:

        let 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".
            }
        }
    
    See more

    Declaration

    Swift

    public protocol UserProtocol : Enrichable