Skip to content

Make emptyObject more developer friendly #269

Closed
@vdkdamian

Description

@vdkdamian

New Feature / Enhancement Checklist

Current Limitation

Currently the developer needs to add a emptyObject to the ParseObject struct

Feature / Enhancement Description

Adding a Updatable protocol

Example Use Case

struct GameScore: ParseObject, Updatable {
    //: Those are required for Object
    var objectId: String?
    var createdAt: Date?
    var updatedAt: Date?
    var ACL: ParseACL?

    //: Your own properties.
    var score: Int = 0
}

var changedScore = savedScore.updatable
changedScore.score = 200
changedScore.save { result in
    switch result {
    case .success(var savedChangedScore):
        print("Succes")

    case .failure(let error):
        assertionFailure("Error saving: \(error)")
    }
}

Alternatives / Workarounds

struct GameScore: ParseObject {
    //: Those are required for Object
    var objectId: String?
    var createdAt: Date?
    var updatedAt: Date?
    var ACL: ParseACL?

    //: Your own properties.
    var score: Int = 0

    /*:
     It's recommended the developer adds the emptyObject computed property or similar.
     Gets an empty version of the respective object. This can be used when you only need to update a
     a subset of the fields of an object as oppose to updating every field of an object. Using an
     empty object and updating a subset of the fields reduces the amount of data sent between
     client and server when using `save` and `saveAll` to update objects.
    */
    var emptyObject: Self {
        var object = Self()
        object.objectId = objectId
        object.createdAt = createdAt
        return object
    }
}

3rd Party References

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions