Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Entry {
- let id : String
- var checked : Bool
- init(_ dic : [String: String]) {
- id = dic["id"]!
- }
- }
- //add to local array if not exist on local
- func addNewEntry(_ response : [[String : String]], _ localArr: inout [Entry] ){
- let localIDset = Set<String>(localArr.reduce([String]()){ $0 + [$1.id] })
- for item in response{
- if !localIDset.contains(item["id"]!){
- localArr.append(Entry(item))
- }
- }
- }
- // remove on local array if not exist on server
- let resp = [["id" : "123"],["id" : "3"],["id" : "23"]]
- var localArray = [Entry]()
- addNewEntry(resp, &localArray)
- print(localArray)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement