Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@erica
Last active February 11, 2017 01:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erica/999dabc1a2d176bce3ec to your computer and use it in GitHub Desktop.
Save erica/999dabc1a2d176bce3ec to your computer and use it in GitHub Desktop.
Composed character count
extension String {
var composedCount : Int {
var count = 0
enumerateSubstringsInRange(startIndex..<endIndex, options: .ByComposedCharacterSequences) {_ in count++}
return count
}
}
@jamesfzhang
Copy link

Swift 3 version:

extension String {
    var composedCount : Int {
        var count = 0
        enumerateSubstrings(in: startIndex..<endIndex, options: .byComposedCharacterSequences) {_ in count += 1}
        return count
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment