0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ObservableマクロでBindingを使う方法

Posted at

booksがObservableだとします。
それで、Viewの中で、@Bindable var book = bookを使います。
すると$book.titleのようにバインディングができます。

正直違和感があるかもしれませんが、公式ドキュメントにそう記載がありますので、とりあえずいいのでしょう。

struct LibraryView: View {
    @State private var books = [Book(), Book(), Book()]


    var body: some View {
        List(books) { book in 
            @Bindable var book = book
            TextField("Title", text: $book.title)
        }
    }
}

以下のページの一番下の項目に記載があります。
https://developer.apple.com/documentation/swiftui/managing-model-data-in-your-app

でわ。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?