<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Character",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SJ"
  },
  "title" : "Character"
}
-->

# Character

A single extended grapheme cluster that approximates a user-perceived
character.

```
@frozen struct Character
```

## Overview

The `Character` type represents a character made up of one or more Unicode
scalar values, grouped by a Unicode boundary algorithm. Generally, a
`Character` instance matches what the reader of a string will perceive as
a single character. Strings are collections of `Character` instances, so
the number of visible characters is generally the most natural way to
count the length of a string.

```
let greeting = "Hello! 🐥"
print("Length: \(greeting.count)")
// Prints "Length: 8"
```

Because each character in a string can be made up of one or more Unicode
scalar values, the number of characters in a string may not match the
length of the Unicode scalar value representation or the length of the
string in a particular binary representation.

```
print("Unicode scalar value count: \(greeting.unicodeScalars.count)")
// Prints "Unicode scalar value count: 8"

print("UTF-8 representation count: \(greeting.utf8.count)")
// Prints "UTF-8 representation count: 11"
```

Every `Character` instance is composed of one or more Unicode scalar values
that are grouped together as an *extended grapheme cluster*. The way these
scalar values are grouped is defined by a canonical, localized, or
otherwise tailored Unicode segmentation algorithm.

For example, a country’s Unicode flag character is made up of two regional
indicator scalar values that correspond to that country’s ISO 3166-1
alpha-2 code. The alpha-2 code for The United States is “US”, so its flag
character is made up of the Unicode scalar values `"\u{1F1FA}"` (REGIONAL
INDICATOR SYMBOL LETTER U) and `"\u{1F1F8}"` (REGIONAL INDICATOR SYMBOL
LETTER S). When placed next to each other in a string literal, these two
scalar values are combined into a single grapheme cluster, represented by
a `Character` instance in Swift.

```
let usFlag: Character = "\u{1F1FA}\u{1F1F8}"
print(usFlag)
// Prints "🇺🇸"
```

For more information about the Unicode terms used in this discussion, see
the [Unicode.org glossary](http://www.unicode.org/glossary/). In particular, this discussion
mentions [extended grapheme clusters](http://www.unicode.org/glossary/#extended_grapheme_cluster) and 
[Unicode scalar
values](http://www.unicode.org/glossary/#unicode_scalar_value).

## Topics

### Creating a Character

In addition to creating a character from a single-character string literal, you can
also convert a unicode scalar value or single-character string.

[`init(_:)`](/documentation/Swift/Character/init(_:)-6o1aq)

Creates a character from a single-character string.

### Writing to a Text Stream

[`write(to:)`](/documentation/Swift/Character/write(to:))

Writes the character into the given output stream.

### Comparing Characters

[`==(_:_:)`](/documentation/Swift/Character/==(_:_:))

Returns a Boolean value indicating whether two values are equal.

[`!=(_:_:)`](/documentation/Swift/Character/!=(_:_:))

Returns a Boolean value indicating whether two values are not equal.

### Working with a Character’s Unicode Values

[`init(_:)`](/documentation/Swift/Character/init(_:)-8hq6x)

Creates a character containing the given Unicode scalar value.

[`unicodeScalars`](/documentation/Swift/Character/unicodeScalars)

[`Character.UnicodeScalarView`](/documentation/Swift/Character/UnicodeScalarView)

[`isASCII`](/documentation/Swift/Character/isASCII)

A Boolean value indicating whether this is an ASCII character.

[`asciiValue`](/documentation/Swift/Character/asciiValue)

The ASCII encoding value of this character, if it is an ASCII character.

### Inspecting a Character

[`isLetter`](/documentation/Swift/Character/isLetter)

A Boolean value indicating whether this character is a letter.

[`isPunctuation`](/documentation/Swift/Character/isPunctuation)

A Boolean value indicating whether this character represents punctuation.

[`isNewline`](/documentation/Swift/Character/isNewline)

A Boolean value indicating whether this character represents a newline.

[`isWhitespace`](/documentation/Swift/Character/isWhitespace)

A Boolean value indicating whether this character represents whitespace,
including newlines.

[`isSymbol`](/documentation/Swift/Character/isSymbol)

A Boolean value indicating whether this character represents a symbol.

[`isMathSymbol`](/documentation/Swift/Character/isMathSymbol)

A Boolean value indicating whether this character represents a symbol
that naturally appears in mathematical contexts.

[`isCurrencySymbol`](/documentation/Swift/Character/isCurrencySymbol)

A Boolean value indicating whether this character represents a currency
symbol.

### Checking a Character’s Case

[`isCased`](/documentation/Swift/Character/isCased)

A Boolean value indicating whether this character changes under any form
of case conversion.

[`isUppercase`](/documentation/Swift/Character/isUppercase)

A Boolean value indicating whether this character is considered uppercase.

[`uppercased()`](/documentation/Swift/Character/uppercased())

Returns an uppercased version of this character.

[`isLowercase`](/documentation/Swift/Character/isLowercase)

A Boolean value indicating whether this character is considered lowercase.

[`lowercased()`](/documentation/Swift/Character/lowercased())

Returns a lowercased version of this character.

### Checking a Character’s Numeric Properties

[`isNumber`](/documentation/Swift/Character/isNumber)

A Boolean value indicating whether this character represents a number.

[`isWholeNumber`](/documentation/Swift/Character/isWholeNumber)

A Boolean value indicating whether this character represents a whole
number.

[`wholeNumberValue`](/documentation/Swift/Character/wholeNumberValue)

The numeric value this character represents, if it represents a whole
number.

[`isHexDigit`](/documentation/Swift/Character/isHexDigit)

A Boolean value indicating whether this character represents a
hexadecimal digit.

[`hexDigitValue`](/documentation/Swift/Character/hexDigitValue)

The numeric value this character represents, if it is a hexadecimal digit.

### Creating a Range Expression

[`...(_:_:)`](/documentation/Swift/Character/...(_:_:))

Returns a closed range that contains both of its bounds.

[`...(_:)`](/documentation/Swift/Character/...(_:)-4mm4x)

Returns a partial range up to, and including, its upper bound.

[`...(_:)`](/documentation/Swift/Character/...(_:)-6ct59)

Returns a partial range extending upward from a lower bound.

### Describing a Character

[`description`](/documentation/Swift/Character/description)

A textual representation of this instance.

[`debugDescription`](/documentation/Swift/Character/debugDescription)

A textual representation of the character, suitable for debugging.

[`customMirror`](/documentation/Swift/Character/customMirror)

A mirror that reflects the `Character` instance.

[`customPlaygroundQuickLook`](/documentation/Swift/Character/customPlaygroundQuickLook)

A custom playground Quick Look for the `Character` instance.

[`hash(into:)`](/documentation/Swift/Character/hash(into:))

Hashes the essential components of this value by feeding them into the
given hasher.

### Infrequently Used Functionality

[`init(extendedGraphemeClusterLiteral:)`](/documentation/Swift/Character/init(extendedGraphemeClusterLiteral:))

Creates a character with the specified value.

[`init(unicodeScalarLiteral:)`](/documentation/Swift/Character/init(unicodeScalarLiteral:))



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)