BoolでStringを分ける

実現したいこと

BoolによるStringの表示分け
(CoreData Entityによる)

SwiftUIを練習しています

A, B, Cの別々のListから
ひとつのListを持つViewに遷移するとき

表示する内容を
Boolの値で分けたいと思っています。

現在は
それぞれ

swift

1List {2 Section(header: Text("Section")) {3 NavigationLink(4 destination: NextView(),5 label: {6 Text("1")7 }8 )9 }10 11Section(header: Text("Section")) {12 NavigationLink(13 destination: NextView(),14 label: {15 Text("2")16 }17 )18 }19 20Section(header: Text("Section")) {21 NavigationLink(22 destination: NextView(),23 label: {24 Text("3")25 }26 )27 }

として

NextViewで

swift

1List {2 ForEach(items) { item in3 NavigationLink {4 SecondView()5 } label: {6 Text(item.text ?? "")7}

としています。

ですが、

これだとどのSectionの Listから遷移しても
同じ表示となってしまいます。

SecondViewでは
item.boolとして
Bool値を持たせています。

そのオンオフでNextView()に表示するtextを変えることはできるでしょうか?

NextView()をNextView1, 2, 3として
それぞれの画面で異なるtextを表示しましたが、SecondViewでそれらの値を一括で扱えないため
セオリー通りではない気がしています。

コメントを投稿

0 コメント