1
1

More than 1 year has passed since last update.

SwiftUIカスタムイニシャライザで@Bindingの初期化方法

Posted at

普段はAndroidのエンジニアをしてますが、SwiftUIを触っていたところ、initが必要なSwiftUIを作成していたところBindingが初期化されてないことにハマったので記載しておこうと思います。

TimeView.swift

    @Binding var dateTextTime: String
    @Binding var nowDate: Date

  init(dateTextTime: Binding<String>,nowDate: Binding<Date>) {
        self._dateTextTime = dateTextTime
        self._nowDate = nowDate
    }

引数の型は Binding<String>と、Binding<Date>です。
名前の前に_を付けることが必要となります。

全然分からず悩みました。

普段Android開発をしてますが昔UI作るのに苦戦していたので、SwiftUiでUIを簡単に作れるようになったので、iOSの開発もやっていこうと思います。

1
1
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
1
1