Created
October 26, 2021 11:58
-
-
Save dilipiOSDeveloper/4af157b4dd2dad5fd06304b0ced62655 to your computer and use it in GitHub Desktop.
Filter from array based on particular key with higher order functions
This file contains 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
var layers = [[String:Any]]() //Array | |
// Note:- Filter key which has currenVersion exists and also status key true | |
let currenVersion = UserDefaults.standard.value(forKey: udCurrentVersion) as? Int ?? 0 | |
var temp = layers.filter { objfilter in | |
if let versions = objfilter["versions"] as? [String] | |
{ | |
return (versions.contains(String(currenVersion)) || versions.contains("1,2") || versions.contains("2,1")) ? (objfilter["status"] as? Bool ?? false) : false | |
} | |
else | |
{ | |
return false | |
} | |
} | |
layers = temp | |
--------------------------------------------------------------------------------------------------- | |
var layers = [[String:Any]]() | |
// Note:- Filter key which has status key true | |
var temp = layers.filter { objfilter in | |
return (objfilter["status"] as? Bool ?? false) ? true : false | |
} | |
print(temp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment