Last active
August 29, 2015 14:10
-
-
Save scheinem/7ea940dc4f1b88e903b3 to your computer and use it in GitHub Desktop.
countElements() bug in Swift?!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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