Swift: Loop through objects and their certain variables -


this question has answer here:

i have class called "man". 1 of variable of man "height" of person.

i have example 10 objects of "man" different values height parameter , want order these objects height. how can achieve this?

var allman:[man] = [man]()     currentman in allman {         //something     } 

let assume allmen array sorted:

var allmen = [man]() 

then, suppose initialised array 10 values. after can sorted allmen in descending order:

var allsortedmen = allmen.sort { $0.height > $1.height } 

explanation:

you should pass function/closure of type isorderedbefore: (self.generator.element, self.generator.element) -> bool

let sortedallmen = allmen.sort { (first: men, second: men -> bool in     return first.height > second.height       // or return first.height < second.height ascending sort order } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -