Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Composed character count
extension String {
var composedCount : Int {
var count = 0
enumerateSubstringsInRange(startIndex..<endIndex, options: .ByComposedCharacterSequences) {_ in count++}
return count
}
}
@jamesfzhang

This comment has been minimized.

Copy link

@jamesfzhang jamesfzhang commented Nov 28, 2016

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