4 ms·
Swift String Cheat Sheet
- steveklabnik 11y ago> 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 11y agoYes, I believe so. From here: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html https://developer.apple.com/library/ios/documentation/Swift/... "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 11y agoNice, thank you for the reference.
- melling 11y agoA 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=strings http://www.h4labs.com/dev/ios/swift_cookbook.html?topic=stri... 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.
- tomp 11y agoAccording 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...).
- cballard 11y agoThose are (or were, at least) bridged from NSString. There's a bunch of path handling stuff available as well, because Swift String can be converted to and from NSString.
- Cyberdog 11y agoYou can use the lowercaseStringWithLocale/uppercaseStringWithLocale methods to explicitly specify which locale to use: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/index.html#//apple_ref/occ/instm/NSString/uppercaseStringWithLocale https://developer.apple.com/library/ios/documentation/Cocoa/...: