ParseObject

public protocol ParseObject: Objectable,
                             Fetchable,
                             Savable,
                             Deletable,
                             Hashable,
                             CustomDebugStringConvertible

Objects that conform to the ParseObject protocol have a local representation of data persisted to the Parse cloud. This is the main protocol that is used to interact with objects in your app.

If you plan to use custom encoding/decoding, be sure to add objectId, createdAt, updatedAt, and ACL to your ParseObject CodingKeys.

Note

It is recommended to make yourParseObjects “value types” (structs). If you are using value types there isn’t much else you need to do but to conform to ParseObject. If you are thinking of using reference types, see the warning.

Warning

If you plan to use “reference types” (classes), you are using at your risk as this SDK is not designed for reference types and may have unexpected behavior when it comes to threading. You will also need to implement your own == method to conform to Equatable along with with the hash method to conform to Hashable. It is important to note that for unsaved ParseObject‘s, you won’t be able to rely on objectId for Equatable and Hashable as your unsaved objects won’t have this value yet and is nil. A possible way to address this is by creating a UUID for your objects locally and relying on that for Equatable and Hashable, otherwise it’s possible you will get “circular dependency errors” depending on your implementation.

Coding

  • getEncoder() Extension method

    The Parse encoder is used to JSON encode all ParseObjects and types in a way meaninful for a Parse Server to consume.

    Declaration

    Swift

    func getEncoder() -> ParseEncoder
  • getJSONEncoder() Extension method

    The JSON encoder setup with the correct dateEncodingStrategy strategy to send data to a Parse Server.

    Declaration

    Swift

    func getJSONEncoder() -> JSONEncoder
  • getDecoder() Extension method

    The JSON decoder setup with the correct dateDecodingStrategy strategy to decode data from a Parse Server. This encoder is used to decode all data received from the server.

    Declaration

    Swift

    func getDecoder() -> JSONDecoder

Combine

  • Fetches the ParseObject aynchronously with the current data from the server and sets an error if one occurs. Publishes when complete.

    Declaration

    Swift

    func fetchPublisher(includeKeys: [String]? = nil,
                        options: API.Options = []) -> Future<Self, ParseError>

    Parameters

    includeKeys

    The name(s) of the key(s) to include that are ParseObjects. Use ["*"] to include all keys. This is similar to include and includeAll for Query.

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

  • savePublisher(options:) Extension method

    Saves the ParseObject asynchronously and publishes when complete.

    Important

    If an object saved has the same objectId as current, it will automatically update the current.

    Declaration

    Swift

    func savePublisher(options: API.Options = []) -> Future<Self, ParseError>

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

  • deletePublisher(options:) Extension method

    Deletes the ParseObject asynchronously and publishes when complete.

    Important

    If an object deleted has the same objectId as current, it will automatically update the current.

    Declaration

    Swift

    func deletePublisher(options: API.Options = []) -> Future<Void, ParseError>

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    A publisher that eventually produces a single value and then finishes or fails.

Default Implementations

  • hasSameObjectId(as:) Extension method

    Determines if two objects have the same objectId.

    Declaration

    Swift

    public func hasSameObjectId<T>(as other: T) -> Bool where T : ParseObject

    Parameters

    as

    Object to compare.

    Return Value

    Returns a true if the other object has the same objectId or false if unsuccessful.

  • toPointer() Extension method

    Gets a Pointer referencing this Object.

    Declaration

    Swift

    public func toPointer() throws -> Pointer<Self>

    Return Value

    Pointer

CustomDebugStringConvertible

  • debugDescription Extension method

    Declaration

    Swift

    public var debugDescription: String { get }

Fetchable

  • fetch(includeKeys:options:) Extension method

    Fetches the ParseObject synchronously with the current data from the server and sets an error if one occurs.

    Throws

    An error of ParseError type.

    Declaration

    Swift

    public func fetch(includeKeys: [String]? = nil,
                      options: API.Options = []) throws -> Self

    Parameters

    includeKeys

    The name(s) of the key(s) to include that are ParseObjects. Use ["*"] to include all keys. This is similar to include and includeAll for Query.

    options

    A set of header options sent to the server. Defaults to an empty set.

  • Fetches the ParseObject asynchronously and executes the given callback block.

    Declaration

    Swift

    public func fetch(
        includeKeys: [String]? = nil,
        options: API.Options = [],
        callbackQueue: DispatchQueue = .main,
        completion: @escaping (Result<Self, ParseError>) -> Void
    )

    Parameters

    includeKeys

    The name(s) of the key(s) to include. Use ["*"] to include all keys.

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute when completed. It should have the following argument signature: (Result<Self, ParseError>).

Savable

  • save(options:) Extension method

    Saves the ParseObject synchronously and throws an error if there’s an issue.

    Throws

    An error of type ParseError.

    Declaration

    Swift

    public func save(options: API.Options = []) throws -> Self

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    Return Value

    Returns saved ParseObject.

  • Saves the ParseObject asynchronously and executes the given callback block.

    Declaration

    Swift

    public func save(
        options: API.Options = [],
        callbackQueue: DispatchQueue = .main,
        completion: @escaping (Result<Self, ParseError>) -> Void
    )

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute. It should have the following argument signature: (Result<Self, ParseError>).

Deletable

  • delete(options:) Extension method

    Deletes the ParseObject synchronously with the current data from the server and sets an error if one occurs.

    Throws

    An error of ParseError type.

    Declaration

    Swift

    public func delete(options: API.Options = []) throws

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

  • Deletes the ParseObject asynchronously and executes the given callback block.

    Declaration

    Swift

    public func delete(
        options: API.Options = [],
        callbackQueue: DispatchQueue = .main,
        completion: @escaping (Result<Void, ParseError>) -> Void
    )

    Parameters

    options

    A set of header options sent to the server. Defaults to an empty set.

    callbackQueue

    The queue to return to after completion. Default value of .main.

    completion

    The block to execute when completed. It should have the following argument signature: (Result<Void, ParseError>).

ParseOperation

ParseRelation

  • relation Extension method

    Create a new relation.

    Declaration

    Swift

    var relation: ParseRelation<Self> { get }
  • relation(_:className:) Extension method

    Create a new relation with a specific key.

    Declaration

    Swift

    func relation(_ key: String, className: String? = nil) -> ParseRelation<Self>

    Parameters

    key

    A key for the relation.

    className

    The name of the child class for the relation.

    Return Value

    A new ParseRelation.

  • relation(_:child:) Extension method

    Create a new relation to a specific child.

    Declaration

    Swift

    func relation<U>(_ key: String, child: U? = nil) -> ParseRelation<Self> where U : ParseObject

    Parameters

    key

    A key for the relation.

    child

    The child ParseObject.

    Return Value

    A new ParseRelation.

Query

  • query() Extension method

    Create an instance with no constraints.

    Declaration

    Swift

    static func query() -> Query<Self>

    Return Value

    An instance of query for easy chaining.

  • query(_:) Extension method

    Create an instance with a variadic amount constraints.

    Declaration

    Swift

    static func query(_ constraints: QueryConstraint...) -> Query<Self>

    Parameters

    constraints

    A variadic amount of zero or more QueryConstraint‘s.

    Return Value

    An instance of query for easy chaining.

  • query(_:) Extension method

    Create an instance with an array of constraints.

    Declaration

    Swift

    static func query(_ constraints: [QueryConstraint]) -> Query<Self>

    Parameters

    constraints

    An array of QueryConstraint‘s.

    Return Value

    An instance of query for easy chaining.