Ambiguous Reference to Member 'Buildblock()'

Ambiguous reference to member 'buildBlock()'

As @Hamish originally mentioned in comments, ViewBuilders cannot exceed over 10 subviews! So you should group items in smaller pieces and try to add them group by group.

So instead of something like this: (This is a working example based on your original code, not exactly the same)

struct ContentView : View {

@State var firstName: String = ""
@State var lastName: String = ""

@State var phoneNumber: String = ""
@State var emailAddress: String = ""

@State var password: String = ""
@State var confirmPassword: String = ""

var body: some View {

ScrollView (showsVerticalIndicator: false) {

TextField($firstName, placeholder: Text("First Name"))
TextField($lastName, placeholder: Text("Last Name"))

Spacer()

TextField($phoneNumber, placeholder: Text("Phone Number"))
TextField($emailAddress, placeholder: Text("Email Address"))

Spacer()

TextField($password, placeholder: Text("Password"))
TextField($confirmPassword, placeholder: Text("Confirm Password"))

// ...

}
.padding()
}

}

Consider breaking it into meaningful smaller groups like this:

struct NameSectionView : View {

@State var firstName: String
@State var lastName: String

var body: some View {
Group {
TextField($firstName, placeholder: Text("First Name"))
TextField($lastName, placeholder: Text("Last Name"))
}
}

}

struct ContactSectionView : View {

@State var phoneNumber: String
@State var emailAddress: String

var body: some View {
Group {
TextField($phoneNumber, placeholder: Text("Phone Number"))
TextField($emailAddress, placeholder: Text("Email Address"))
}
}

}

struct PasswordSectionView : View {

@State var password: String
@State var confirmPassword: String

var body: some View {
Group {
TextField($password, placeholder: Text("Password"))
TextField($confirmPassword, placeholder: Text("Confirm Password"))
}
}

}

and use them like this:

struct ContentView : View {

@State var firstName: String = ""
@State var lastName: String = ""

@State var phoneNumber: String = ""
@State var emailAddress: String = ""

@State var password: String = ""
@State var confirmPassword: String = ""

var body: some View {

ScrollView (showsVerticalIndicator: false) {

NameSectionView(firstName: firstName, lastName: lastName)

Spacer()

ContactSectionView(phoneNumber: phoneNumber, emailAddress: emailAddress)

Spacer()

PasswordSectionView(password: password, confirmPassword: confirmPassword)

// ...

}
.padding()
}

}

Also this is more reusable if you ever want to use any of this somewhere else.

Ambiguous reference to member 'tableView'

You need to declare your tableView up by your other @IBOutlets since you are using a UIViewController and putting a tableView within it's view. Currently the UIViewController doesn't know what tableView you are referring too.

@IBOutlet var tableView: UITableView!

Then link it up in the interface builder as you have done with your other @IBOutlets. Make sure you link the delegate and dataSource properties of your tableView back to the view controller as well.

To do the latter, after you select your tableView, select the Connections Inspector area, as shown in the picture below, and connect them back to your UIViewController.

Sample Image

Are there maximum limits to VStack?

SwiftUI uses ViewBuilder to construct the views that make up many SwiftUI views, like VStack, HStack, List, etc. If you take a look at the ViewBuilder documentation, you'll see that the buildBlock function has many copies, each with a different amount of views as arguments. The function with the most amount of views only takes in 10 views which is why you are seeing the limitation that you observed. A way to work around this is by using Groups:

VStack {
Group {
Text("Placeholder 0")
Text("Placeholder 1")
Text("Placeholder 2")
Text("Placeholder 3")
Text("Placeholder 4")
Text("Placeholder 5")
Text("Placeholder 6")
Text("Placeholder 7")
Text("Placeholder 8")
Text("Placeholder 9")
}
Group {
Text("Other Placeholder 10")
Text("Other Placeholder 11")
Text("Other Placeholder 12")
Text("Other Placeholder 13")
Text("Other Placeholder 14")
Text("Other Placeholder 15")
Text("Other Placeholder 16")
Text("Other Placeholder 17")
Text("Other Placeholder 18")
Text("Other Placeholder 19")
}
}

Although if you want 20 views that are really similar to each other, it is encouraged to use something like a ForEach to avoid making your views too bloated. The above workaround should only be used if the >10 views are truly unique. Even then, a more SwiftUI-y method would be to split up these views into more smaller views:

VStack {
SingleDigitPlaceholders()
TeensPlaceholders()
}

struct SingleDigitPlaceholders: View {
var body: some View {
ForEach(0..<10) { i in
Text("Placeholder \(i)")
}
}
}
struct TeensPlaceholders: View {
var body: some View {
ForEach(10..<20) { i in
Text("Other Placeholder \(i)")
}
}
}

Of course, in this specific example, you can just have the two ForEachs in the original view, but in more complex cases, the point still stands. For example, in a form with many elements (e.g. in a job application form: first name, last name, address, phone number text fields, education dropdown menus, date fields, etc.) you can still split up one view into smaller components (in the job application example - a personal information view, an educational information view, etc.).

Ambiguous reference to member 'subscript'

The problem is that Keys.items is of type Keys, not of type String. The solution is to index with Keys.items.rawValue instead of Keys.items.

Error Ambiguous reference to member 'indices' in SwiftUI

struct ForEach is only using for showing views:

/// A structure that computes views on demand from an underlying collection of
/// of identified data.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct ForEach<Data, ID, Content> where Data : RandomAccessCollection, ID : Hashable { ... }

for example you can use it to show rows of some List

List {
ForEach(dateList.indices, id: \.self) { dateIndex in Text("\(self.dateList[dateIndex])") }
}

it's not about computing some variable like que, you should extract this computing into some function and call it from onAppear for example. Here is a little example of ForEach and forEach difference:

struct SomeLoopData: View {

@State var dates = ["2020/02/28", "2020/02/29"]
var body: some View {
List {
ForEach(dates.indices) { index in Text("\(self.dates[index])") }
.onAppear {
self.compute()
}
}

}

func compute() {

dates.indices.forEach { index in
print(dates[index])
}

}
}


Related Topics



Leave a reply



Submit