Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Last active September 1, 2015 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonsongithub/5f197158dcda14088697 to your computer and use it in GitHub Desktop.
Save sonsongithub/5f197158dcda14088697 to your computer and use it in GitHub Desktop.
Code snippets for Swift symposium #2
// About character counting in UTF-8 and Swift
var str = "かきくがぎぐ🇯🇵"
str.characters.count
str.unicodeScalars.count
let s1 = "\u{E9}"
let s2 = "\u{65}\u{301}"
// Compatibility equivalence and Canonical Equivalent
(s1 == s2)
(s1 as NSString) == (s2 as NSString)
let a = (s1 as NSString).compare(s2)
a.rawValue
let taka1 = "高"
let taka2 = "髙" // ハシゴの方
let isEq = (taka1 == taka2)
// overloadの評価基準がSwiftに明確に書かれていない
func hoge(hoge:String) -> Int {
return 1
}
func hoge(hoge:Int) -> Int {
return 2
}
func hoge(hoge:AnyObject) -> Int {
return 3
}
hoge("a")
hoge("a" as NSString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment