Skip to content

Instantly share code, notes, and snippets.

@scheinem
Last active August 29, 2015 14:10
Show Gist options
  • Save scheinem/7ea940dc4f1b88e903b3 to your computer and use it in GitHub Desktop.
Save scheinem/7ea940dc4f1b88e903b3 to your computer and use it in GitHub Desktop.
countElements() bug in Swift?!
/**
* Is this a bug or is this the way as it is designed by Apple?
* I can't think that this isn't a bug but who knows...
*/
var str = "\r\n"
countElements(str) // Returns 1
(str as NSString).length // Returns 2
/**
* This only happens for the combination of '\r' and '\n'
*
* NOT for '\r' or '\n' alone
*/
var strN = "\n"
countElements(strN) // returns 1
(strN as NSString).length // returns 1
var strR = "\r"
countElements(strR) // returns 1
(strR as NSString).length // returns 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment