Swift Sort sort Function usage

Source: Internet
Author: User

Jane Book Address: Http://www.jianshu.com/p/ad71c94e7bc6

An example of a simple translation made in a few minutes by StackOverflow's question and answer

Direct code, but more explanation

//这是我们的modelclass imageFile  {    varString()    var fileID = Int()}
//使用var images : [imageFile] = []images.sort$0$1.fileID })
The following is the advanced use of closures
//General Code Form Images.sort({(Image1:imagefile, image2:imagefile), Bool  in return Image1.fileid > Image2.fileid}) 
      Omitted(-)The formImages.Sort({image1, image2  in return Image1.fileid > Image2.fileid})Simple closure form with return valueImages.Sort({image1, image2  in Image1.fileid > Image2.fileid})The form of an implied parameterImages.Sort({$0. ) FileID > $1. FileID})The following results are all the same, just different forms of writingImages=Images.Sorted({(Image1:imagefile, image2:imagefile), Bool  in return Image1.fileid > Image2.fileid}) 
      Images=Images.Sorted({image1, image2  in return Image1.fileid > Image2.fileid})Images=Images.Sorted({image1, image2  in Image1.fileid > Image2.fileid})Images=Images.Sorted({$0. ) FileID > $1. FileID})
//Swift Standard library sort(&images, {(Image1:imagefile, image2:imagefile), Bool  in return Image1.fileid > Image2.fileid})Sort(&images, {image1, image2  in return Image1.fileid > Image2.fileid})Sort(&images, {image1, image2  in Image1.fileid > Image2.fileid})Sort(&images, {$0. ) FileID > $1. FileID})How to useImages=Sorted(images, {(Image1:imagefile, image2:imagefile), Bool  in return image1.fileid > image 2.fileID})Images=Sorted(images, {image1, image2  in return Image1.fileid > Image2.fileid})Images=Sorted(images, {image1, image2  in Image1.fileid > Image2.fileid})Images=Sorted(images, {$0. ) FileID > $1. FileID})

Swift Sort sort Function usage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.