<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Text/init(_:format:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4TextV_6formatAC11FormatInputQz_xtc10Foundation0E5StyleRzSQAFRQAG16AttributedStringV0E6OutputRtzlufc::OverloadGroup"
  },
  "title" : "init(_:format:)"
}
-->

# init(_:format:)

Creates a text view that displays the formatted representation
of a nonstring type supported by a corresponding format style.

```
init<F>(_ input: F.FormatInput, format: F) where F : FormatStyle, F.FormatInput : Equatable, F.FormatOutput == AttributedString
```

## Parameters

`input`

The underlying value to display.

`format`

A format style of type `F` to convert the underlying value
of type `F.FormatInput` to an attributed string representation.

## Discussion

Use this initializer to create a text view backed by a nonstring
value, using a
<doc://com.apple.documentation/documentation/Foundation/FormatStyle>
to convert the type to an attributed string representation. Any changes to the value
update the string displayed by the text view.

In the following example, three [`Text`](/documentation/SwiftUI/Text) views present a date with
different combinations of date and time fields, by using different
<doc://com.apple.documentation/documentation/Foundation/Date/FormatStyle>
options.

```
@State private var myDate = Date()
var body: some View {
    VStack {
        Text(myDate, format: Date.FormatStyle(date: .numeric, time: .omitted).attributedStyle)
        Text(myDate, format: Date.FormatStyle(date: .complete, time: .complete).attributedStyle)
        Text(myDate, format: Date.FormatStyle().hour(.defaultDigitsNoAMPM).minute().attributedStyle)
    }
}
```

![Three vertically stacked text views showing the date with different](images/com.apple.SwiftUI/Text-init-format-1@2x.png)

---

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)