Skip to content

Instantly share code, notes, and snippets.

@allevato

allevato/foo.md Secret

Last active November 23, 2017 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allevato/ae267e2aaaa7939d6233d66a87b48fc0 to your computer and use it in GitHub Desktop.
Save allevato/ae267e2aaaa7939d6233d66a87b48fc0 to your computer and use it in GitHub Desktop.

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