
Swift String Cheat Sheet - ingve
http://useyourloaf.com/blog/swift-string-cheat-sheet.html
======
steveklabnik

      > Swift is Unicode correct so the equality operator (“==”) checks 
      > for Unicode canonical equivalence.
    

I think this is what this implies, but does Swift do grapheme
canonicalization/normalization here? And which one? It might be worth adding
the "Noël problem" here.

~~~
pkaler
Yes, I believe so. From here:
[https://developer.apple.com/library/ios/documentation/Swift/...](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html)

"Every instance of Swift’s Character type represents a single extended
grapheme cluster. An extended grapheme cluster is a sequence of one or more
Unicode scalars that (when combined) produce a single human-readable
character."

And then later:

"For example, LATIN SMALL LETTER E WITH ACUTE (U+00E9) is canonically
equivalent to LATIN SMALL LETTER E (U+0065) followed by COMBINING ACUTE ACCENT
(U+0301). Both of these extended grapheme clusters are valid ways to represent
the character é, and so they are considered to be canonically equivalent"

~~~
steveklabnik
Nice, thank you for the reference.

------
tomp
According to my (admittedly limited) understamding of Unicode, they did almost
everything correctly. The only issue I see is with the 'uppercase'/'lowercase'
functions, which use algorithms that depend on locale; I wonder which locale
Swift assumes (hopefully not some global one...).

~~~
Cyberdog
You can use the lowercaseStringWithLocale/uppercaseStringWithLocale methods to
explicitly specify which locale to use:
[https://developer.apple.com/library/ios/documentation/Cocoa/...](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/index.html#//apple_ref/occ/instm/NSString/uppercaseStringWithLocale):

------
melling
A couple missing useful things to know how to do are split, join, and trim,
which I have on a page:

[http://www.h4labs.com/dev/ios/swift_cookbook.html?topic=stri...](http://www.h4labs.com/dev/ios/swift_cookbook.html?topic=strings)

Something that's not on either page but if you use SQLite, it's important to
be able to convert a C string:

let str:String =
String.fromCString(UnsafePointer<CChar>(sqlite3_column_text(statement,
columnCtr)))!

Make sure you don't have NULL columns.

