ios - How does the Swift string more than operator work -
this question has answer here:
i don't have experience swift , come php / python / javascript background, please bare me.
i reading documentation on swift programming language, when came across the following code snippet:
let names = ["chris", "alex", "ewa", "barry", "daniella"] func backwards(s1: string, _ s2: string) -> bool { return s1 > s2 } names.sort(backwards) // ["ewa", "daniella", "chris", "barry", "alex"]
what don't seem able find, how >
operator works in context, thought count amount of characters , return boolean based on that, logic following snippet should return false:
"cd" > "abc" // true
could please explain going on here? thank you.
i believe javascript uses same string comparison approach, , same syntax. in javascript use localecompare()
. , in swift alternatively use localizedcompare(_:)
(or 1 of other string comparison functions). they're different ways, , different options, alphabetically compare strings.
Comments
Post a Comment