<!--
{
  "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/String/init(_:)-2t931",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SSyS2S17UnicodeScalarViewVcfc"
  },
  "title" : "init(_:)"
}
-->

# init(_:)

Creates a string corresponding to the given collection of Unicode
scalars.

```
init(_ unicodeScalars: String.UnicodeScalarView)
```

## Parameters

`unicodeScalars`

A collection of Unicode scalar values.

## Discussion

You can use this initializer to create a new string from a slice of
another string’s `unicodeScalars` view.

```
let picnicGuest = "Deserving porcupine"
if let i = picnicGuest.unicodeScalars.firstIndex(of: " ") {
    let adjective = String(picnicGuest.unicodeScalars[..<i])
    print(adjective)
}
// Prints "Deserving"
```

The `adjective` constant is created by calling this initializer with a
slice of the `picnicGuest.unicodeScalars` view.

---

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)