List に lineLimit が存在しないため
エラーが発生していると思われます。
lineLimit は Text の機能だったと
記憶しています。
また、コメント欄の
hoshi-takanori さんの修正案も
適用する必要があります。
SwiftUI
1import SwiftUI
2
3struct ContentView: View {
4 @State var pinned = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"]
5 @State var lineLimit = false
6 var body: some View {
7 ZStack{
8 NavigationView {
9 List{
10 Section(header: Text("テキスト")){
11 ForEach(0..<pinned.prefix(lineLimit ? 5 : 10).count, id: \.self) {index in NavigationLink(destination: SecondView(lineLimit: $lineLimit), label: {Text(pinned[index])})
12 }
13 }
14 }
15 }
16 }
17 }
18}
19struct SecondView: View {
20 @Binding var lineLimit: Bool
21 var body: some View {
22 NavigationView {
23 ZStack{
24 Toggle(isOn: $lineLimit) {Text("Toggle")}
25 }
26 }
27 }
28}
↑ List の行数を変更する場合
SwiftUI
1import SwiftUI
2
3struct ContentView: View {
4 @State var pinned = ["111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "test"]
5 @State var lineLimit = [false, false, false]
6 var body: some View {
7 ZStack{
8 NavigationView {
9 List{
10 Section(header: Text("テキスト")){
11 ForEach(0..<pinned.count, id: \.self) {index in NavigationLink(destination: SecondView(lineLimit: $lineLimit[index]), label: {lineLimit[index] ? Text(pinned[index]).lineLimit(1) : Text(pinned[index]).lineLimit(2)})
12 }
13 }
14 }
15 }
16 }
17 }
18}
19struct SecondView: View {
20 @Binding var lineLimit: Bool
21 var body: some View {
22 NavigationView {
23 ZStack{
24 Toggle(isOn: $lineLimit) {Text("Toggle")}
25 }
26 }
27 }
28}
↑Text の行数を指定したい場合(lineLimit)
SwiftUI
1import SwiftUI
2
3struct ContentView: View {
4 @State var pinned = ["111112222233333", "111112222233333", "test"]
5 @State var lineLimit = [false, false, false]
6 var body: some View {
7 ZStack{
8 NavigationView {
9 List{
10 Section(header: Text("テキスト")){
11 ForEach(0..<pinned.count, id: \.self) {index in NavigationLink(destination: SecondView(lineLimit: $lineLimit[index]), label: {lineLimit[index] ? Text(pinned[index].prefix(5)) : Text(pinned[index].prefix(10))})
12 }
13 }
14 }
15 }
16 }
17 }
18}
19struct SecondView: View {
20 @Binding var lineLimit: Bool
21 var body: some View {
22 NavigationView {
23 ZStack{
24 Toggle(isOn: $lineLimit) {Text("Toggle")}
25 }
26 }
27 }
28}
↑Text の文字数を指定したい場合(prefix)