Swift - Extra Argument in Call

Swift - Extra Argument in call

In some cases, "Extra argument in call" is given even if the call looks right, if the types of the arguments don't match that of the function declaration. From your question, it looks like you're trying to call an instance method as a class method, which I've found to be one of those cases. For example, this code gives the exact same error:

class Foo {

func name(a:Int, b: Int) -> String {
return ""
}
}

class Bar : Foo {
init() {
super.init()
Foo.name(1, b: 2)
}
}

You can solve this in your code by changing your declaration of setCity to be class func setCity(...) (mentioned in the comments); this will allow the ViewController.setCity call to work as expected, but I'm guessing that you want setCity to be an instance method since it appears to modify instance state. You probably want to get an instance to your ViewController class and use that to call the setCity method. Illustrated using the code example above, we can change Bar as such:

class Bar : Foo {    
init() {
super.init()
let foo = Foo()
foo.name(1, b: 2)
}
}

Voila, no more error.

SwiftUI: Random Extra argument in call error

try making a Group { } around your views. just 10 are allowed in Swiftui...with group you can add more. or use subviews...(would be cleaner code too)

Extra argument in call when I call struct 11 times but not 10 times or lower

The closure that HStack (and many other views) accept is a kind of function builder called ViewBuilder. It only supports up to 10 Views as arguments. These are all hardcoded in the SwiftUI module:

static func buildBlock<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8, _ c9: C9) -> TupleView<(C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where C0 : View, C1 : View, C2 : View, C3 : View, C4 : View, C5 : View, C6 : View, C7 : View, C8 : View, C9 : View

The designers could hardcode more, but decided not to. This is probably because you can simplify your view's code to not need to put that many views in a view builder.

In this case, you can use a ForEach:

HStack {
ForEach(0..<11) { i in
BarView(barGradeValue: i, barSendValue: i < 6 ? (i + 1) * 10 : (11 - i) * 10, barFlashValue: 10)
}
}

Extra argument in call Spacer()

Note Spacer() is a view, and so you are exceeding the number of views (10) allowed inside another view. Try some variations of this, or use Group {...}:

struct ContentView: View {

var cardView: some View {
Group {
Spacer()
HStack {
Spacer()
Image("card3")
Spacer()
Image("card4")
Spacer()
}
Spacer()
}
}

var textview: some View {
Group {
Spacer()
HStack{
Spacer()
Text("0")
Spacer()
Text("0")
Spacer()
}
Spacer()
}
}

var devView: some View {
Group {
Spacer()
HStack{
Spacer()
Text("Player")
Spacer()
Text("CPU")
Spacer()
}
Spacer()
}
}

var body: some View {
ZStack{
Image("background")
.ignoresSafeArea()
VStack{
Spacer()
Image("logo")
Spacer()
cardView
Image("dealbutton")
devView
.font(.title)
.foregroundColor(.white)
textview
Spacer()
}
}
}
}

SwiftUI Problem! Extra argument in call

If it is not copy-paste, then the error is

Button("10") {

let selectionFeedback = UISelectionFeedbackGenerator()
selectionFeedback.selectionChanged()

self.show2010.toggle()
}
.buttonStyle(YearRoundedButton())
_10L() // << here !!

If looks like (based on common patten) you missed .sheet here.

Extra argument call in Swift

You have to assign the predicate to the request.

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
let request: NSFetchRequest<Item> = Item.fetchRequest()
print(searchBar.text!)

request.predicate = NSPredicate(format: "title CONTAINS[cd] %@", searchBar.text!)

request.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)]

loadItems(with: request)

self.tableView.reloadData() //for reloading the table view
}

And this should work fine.

SwiftUi Extra Argument in Call When calling two views of @EnvironmentObject in main view

You cannot just throw in several views into the body of a View. How would those views be displayed?

You need to wrap them in a stack, depending on your needs, either a VStack, HStack or ZStack.

If you want them to be vertically stacked for instance, use a VStack.

struct MainView: View {

@EnvironmentObject var userInterestVM: User_Interests_ViewModel

var body: some View {
VStack {
FirstEnvironmentObjectView()
FirstEnvironmentObjectView()
}
}
}

As for the environment object, you don't need to manually inject them into FirstEnvironmentObjectView from MainView, because EnvironmentObjects are injected into the view hierarchy downstream (so to all subviews of the parent view) and hence by injecting a User_Interests_ViewModel as an EnvironmentObject into MainView, it gets automatically injected into all FirstEnvironmentObjectViews created inside MainView.

Getting the error Extra Argument in Call SwiftUi

You have to use Group in more than 10 item in body! as you can see in my code, also inside a Group you can have just 10 item!

var body: some View {


VStack {

Text("Booking End Times")
.font(.title)
.fontWeight(.bold)

List {

Group { // <<: Here


HStack {

Text("Table 1 -")
.onTapGesture {
timeForShow1 = getCurrentTime
table1.toggle()
}


if table1 { Text(timeForShow1 ?? "not available!") }

}

HStack {

Text("Table 2 -")
.onTapGesture {
timeForShow2 = getCurrentTime
table2.toggle()
}


if table2 { Text(timeForShow2 ?? "not available!") }

}

HStack {

Text("Table 3 -")
.onTapGesture {
timeForShow3 = getCurrentTime
table3.toggle()
}


if table3 { Text(timeForShow3 ?? "not available!") }

}

HStack {

Text("Table 4 -")
.onTapGesture {
timeForShow4 = getCurrentTime
table4.toggle()
}


if table4 { Text(timeForShow4 ?? "not available!") }

}

HStack {

Text("Table 5 -")
.onTapGesture {
timeForShow5 = getCurrentTime
table5.toggle()
}


if table5 { Text(timeForShow5 ?? "not available!") }

}


}


Group { // <<: Here

HStack {

Text("Table 6 -")
.onTapGesture {
timeForShow6 = getCurrentTime
table6.toggle()
}


if table6 { Text(timeForShow6 ?? "not available!") }

}

HStack {

Text("Table 7-")
.onTapGesture {
timeForShow7 = getCurrentTime
table7.toggle()
}


if table7 { Text(timeForShow7 ?? "not available!") }

}

HStack {

Text("Table 8 -")
.onTapGesture {
timeForShow8 = getCurrentTime
table8.toggle()
}


if table8 { Text(timeForShow8 ?? "not available!") }

}

HStack {

Text("Table 9 -")
.onTapGesture {
timeForShow9 = getCurrentTime
table9.toggle()
}


if table9 { Text(timeForShow9 ?? "not available!") }

}

HStack {

Text("Table 10 -")
.onTapGesture {
timeForShow10 = getCurrentTime
table10.toggle()
}


if table10 { Text(timeForShow10 ?? "not available!") }

}


HStack {

Text("Table 11 -")
.onTapGesture {
timeForShow11 = getCurrentTime
table11.toggle()
}


if table11 { Text(timeForShow11 ?? "not available!") }

}

}





}

}




}

Extra arguments at positions #11, #12 in call SwiftUI

ViewBuilder supports only no more than 10 static views in one container... that's a reason of your error

Just group them

Group {

TextField("Class 1-1", text: $class11)

TextField("Class 1-2", text: $class12)

TextField("Class 1-3", text: $class13)

TextField("Class 1-4", text: $class14)

TextField("Class 2-1", text: $class21)

TextField("Class 2-2", text: $class22)

TextField("Class 2-3", text: $class23)

TextField("Class 2-4", text: $class24)

}

backup

Extra Argument In Call?

Your code has two critical flaws:

The definition of PostStruct should be something like this:

struct PostStruct {
let title: String
let message : String
}

The line let title = String!.self declares your title as having a class object, not String.

And another is the line DatabaseViewController:

var posts = [post]

In your code, post is a method, I believe you do not want an Array of methods.

Which should be something like this:

var posts: [PostStruct] = []

And to make two fixes above to work, you need a little more:

        self.posts.insert(PostStruct(title: title ?? "", message: message ?? ""), at: 0)

You may have some other faults in your code, but at least you need the fixes above. Try them.



Related Topics



Leave a reply



Submit