Created
December 14, 2015 08:15
-
-
Save lynxerzhang/f926a2b35970b70d0e11 to your computer and use it in GitHub Desktop.
Jared Davidson's swift sort demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Jared Davidson's swift sort demo | |
//run in xcode 7.1 and swift 2.1 | |
var ary = [0, 10, 8, 2] | |
ary = ary.sort({ $0 < $1 }) | |
print(ary) | |
//[0, 2, 8, 10] | |
var strs = ["objectivec", "swift", "js", "as"] | |
strs.sortInPlace({$0 < $1}) | |
print(strs) | |
//["as", "js", "objectivec", "swift"] | |
struct DataObj { | |
let version: Double | |
let dataValue: String | |
} | |
var structAry: [DataObj] = [DataObj(version: 3, dataValue: "as"), DataObj(version: 2, dataValue: "ObjectiveC"), DataObj(version: 2.1, dataValue: "Swift")] | |
structAry.sortInPlace({$0.version < $1.version}) | |
print(structAry) | |
//[DataObj(version: 2.0, dataValue: "ObjectiveC"), DataObj(version: 2.1, dataValue: "Swift"), DataObj(version: 3.0, dataValue: "as")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment