Created
March 17, 2017 22:51
-
-
Save juzooda/200001c1e0399dec948ead4c5a1d431e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
func createSetWith(enable: Bool, requestList: [[String : Any]]) -> Set<String> { | |
return Set(requestList | |
.filter { ($0["enabled"] as? Bool) == enable } | |
.map { $0["key"] as? String ?? ""}) | |
} | |
let sub1 = ["key" : "updates", "enabled": false] as [String : Any] | |
let sub2 = ["key" : "news", "enabled": true] as [String : Any] | |
let sub3 = ["key" : "itinerary", "enabled": false] as [String : Any] | |
let sub4 = ["key" : "cancelations", "enabled": true] as [String : Any] | |
let requestList = [sub1, sub2, sub3, sub4] | |
let disabledSubscriptions = ["news", "itinerary"] | |
let listToEnable = createSetWith(enable: true, requestList: requestList) | |
let listToDisable = createSetWith(enable: false, requestList: requestList) | |
let setDisabledSubscriptions = Set(disabledSubscriptions) | |
let newSet = setDisabledSubscriptions | |
.subtracting(listToEnable) | |
.union(listToDisable) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment