No Exact Matches in Call to Instance Method Error Message in Swift

No exact matches in call to instance method error message in Swift

Why Xcode Yelling?

Maybe message text seems a little bit self-explanatory but just because Xcode does not exactly point the parameter itself, a little bit hard to figurate for the first time.

Xcode yelling because the method wants to see exact parameter types on the method call, that easy.

Solution for the example case:

var request: URLRequest? = nil

let task = URLSession.shared.dataTask(
with: request!,
completionHandler: { data, response, error in
DispatchQueue.main.async(execute: {

})
})
task.resume()

Just used the URLRequest instead of the NSMutableURLRequest.

Solution for a SwiftUI Example

Let's assume this is your UI:

        ZStack() {
Image(systemName: "photo")
.resizable()
.aspectRatio(contentMode: .fit)
.background(Color.green)
.foregroundColor(Color.white)
.cornerRadius(12)
Text(getToday())
.font(.headline)
}
}

And this is the method that you're calling in the Text(...):

    func getToday() -> Any?
{
let now = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.day], from: now)
return components.day

}

In the example above solution would be changing Any? to a String type.

No exact matches in call to instance method '* * *'

This is a general error message for using the wrong type in the method calls. That's why I added here to help others.

I hope this answer will help some of you guys.

Best.

Why does my Swift get build error: No exact matches in call to instance method 'append'

Just replace your code by:

func my_func() {
var ring_sensors_input: [Ring_Sensors_Input_struct] = []
ring_sensors_input.append(Ring_Sensors_Input_struct(ts:1657150485.0, temp: 235, hr: 95, spO2: 97, rr: 16, steps: 235))
ring_sensors_input.append(Ring_Sensors_Input_struct(ts: 1657150486.0, temp: 238, hr: 92, spO2: 98, rr: 14, steps: 238))
}

The problem is if you want to append an object, like your structure, you have to call it inside the append method. If you don't, the code doesn't know what you are trying to add.



Related Topics



Leave a reply



Submit