引数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付きの変数の値の初期化が無効になる