I have the following structure
aSectionArray = [[objA, objB, objC], [obj1, obj2, obj3], [objX, objY, objZ]]
objA is having a bool, say isEnabled.
I need to filter the aSectionArray based this bool (say isEnabled == true).
Help needed.
I have the following structure
aSectionArray = [[objA, objB, objC], [obj1, obj2, obj3], [objX, objY, objZ]]
objA is having a bool, say isEnabled.
I need to filter the aSectionArray based this bool (say isEnabled == true).
Help needed.
You could use flatten() and filter, like this (Swift 2):
let result = aSectionArray.flatten().filter { $0.isEnabled }
it will give you the objects where isEnabled is true.
We use flatten() to make the 2D array into a 1D array, and we use filter to get the objects where the closure verifies.
In Swift 3 (Xcode 8 beta 6) flatten has become joined:
let result = aSectionArray.joined().filter { $0.isEnabled }