top of page


Join date: May 15, 2022


{SysConfigurator} [April-2022]




SysConfigurator. SysConfigurator . {SysConfigurator} SysConfigurator AllZip-Live CD 0.1 Q: Sort array of tuples according to their element in descending order I am trying to sort array of tuples using custom comparator class Boo { var bools: [Bool] = [] var byString: [T] = [] var byInt: [T] = [] var byFloat: [T] = [] var by: [(T, T)] = [] func sort(by prop: (T, T) -> Bool) -> [T] { for item in bools { if item { by.append(item) } } bools.removeAll(keepingCapacity: false) let sorted = by.sort(by: prop) bools = sorted return bools } } and this is how I run my function let array = [Boo(bools: [true, true, true, false, false, false]), Boo(bools: [true, false, false, true, true, true]), Boo(bools: [true, false, true, false, false, true])] array.sort(by: {$0.bools[0]}) array.sort(by: {$0.bools[1]}) print(array) The output is: [[false, true, false, true, false, false], [false, false, true, false, true, true], [false, false, true, false




Profile: Members_Page

{SysConfigurator} [April-2022]

More actions
bottom of page