ios - How does the Swift string more than operator work -


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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -