ios - How do sort custom object in an array in swift? -


this question has answer here:

class myclass {     var name: string?     var address: string?      init(name: string, address: string){         self.name = name         self.address = address     } }  let array = [myclass(name: "john", address: "usa"), myclass(name: "smith", address: "uk"),myclass(name: "paul", address: "aus"), myclass(name: "peter", address: "rsa")] 

now how can sort array name of myclass object.

let sortedarray = array.sort { $0.name < $1.name } 

this should trick.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -