Skip to content

Instantly share code, notes, and snippets.

@allevato allevato/foo.md Secret
Last active Nov 23, 2017

Embed
What would you like to do?

One scalar, one character

Welcome to Apple Swift version 4.0.2 (swiftlang-900.0.69.1 clang-900.0.38). Type :help for assistance.
  1> let c1: Character = "a"
c1: Character = {
  _representation = smallUTF16 {
    smallUTF16 = 97
  }
}

Two scalars but one character

  2> let c2: Character = "a\u{0300}"
c2: Character = {
  _representation = smallUTF16 {
    smallUTF16 = 50331745
  }
}

Five scalars but one character (black man shrugging emoji)

  3> let c3: Character = "\u{1F937}\u{1F3FF}\u{200D}\u{2642}\u{FE0F}"
c3: Character = {
  _representation = large {
    large = {
      _nativeBuffer = 0x8000000100403670
    }
  }
}

Two characters

  4> let c4: Character = "ab"
error: repl.swift:4:21: error: cannot convert value of type 'String' to specified type 'Character'
let c4: Character = "ab"
                    ^~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.