swift 2中sort和sortInPlace之间的区别?

Ank*_*oel 6 swift swift2

我一直在尝试在swift中使用sortInPlace函数,但它无法正常工作.当我使用sort函数而不是sortinplace时,它可以工作.

请解释这两个功能之间的区别.如果您可以提供演示两种功能使用的小代码示例,那将非常有用.

小智 14

var mutableArray = [19, 7, 8, 45, 34]

// function sort sorts the array but does not change it. Also it has return

mutableArray.sort()

mutableArray
// prints 19, 7, 8, 45, 34

// function sortInPlace will mutate the array. Do not have return

mutableArray.sortInPlace()

mutableArray
// prints 7, 8, 19, 34, 45
Run Code Online (Sandbox Code Playgroud)