Untitled

 avatar
unknown
swift
3 years ago
1.1 kB
3
Indexable
class LocalObject
{
    let uuid: String

    init(uuid: String)
    {
        self.uuid = uuid
    }

    func persist()
    {
        print("Object with UUID \(self.uuid) persisted")
    }

    func delete()
    {
        print("Object with UUID \(self.uuid) deleted")
    }
}

class ServerObject {
    let uuid: String

    init(uuid: String)
    {
        self.uuid = uuid
    }
}

// Problem:
// Syncing is necessary when you need to maintain the same data on a server and client. 
// We want you to write a method called sync, that takes data from a server and persists data that does not exist locally. 
// The data on the server and the client have the property UUID which indicates the same object on the client and the server.
// 
// Example:
sync(serverData: [ServerObject(uuid: "1"), ServerObject(uuid: "3"), ServerObject(uuid: "4")], localData: [LocalObject(uuid: "1"), LocalObject(uuid: "2")])
// >> Object with UUID 3 persisted 
// >> Object with UUID 4 persisted


func sync(serverData: [ServerObject], localData: [LocalObject]) {
    // Implement here
}
Editor is loading...