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 3 years have passed since last update.

@State 変数を他の引数で初期化する

Last updated at Posted at 2021-05-19

引数studentで他の@State変数を初期化しています。

Xcode: Version 12.4

import SwiftUI

struct ChildView: View {
    @ObservedObject var student: Student   //Student: CoreDataのEntity

    @State var name0: String
    @State var num0: Int

    init(student: Student){
        _name0 = State(initialValue: student.name!)
        _num0 = State(initialValue: student.num)
        _student = ObservedObject(initialValue: student)
   }
   var body: some View {
      ...
   }
}


参考:
https://ja.stackoverflow.com/questions/63943/state付きの変数の値の初期化が無効になる

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?