Cannot Convert Value of Type 'X' to Expected Argument Type 'X'

Cannot convert value of type 'x' to expected argument type '[String : Any]'

You are using an object of the struct userMap instead of using a dictionary. You can fix this by creating a dictionary inside the userMap struct and providing that dictionary as the parameter. Since your struct already conforms to Codable you can create Data from object of userMap using JSONEncoder. Then you can convert the data to a JSON dictionary to use as a parameter. Here the code:

struct userMap: Codable {
//...
var dictionary: [String: Any] {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}
}

And for the setData:

try dbRef.document(docRefID).setData(from: user.dictionary)

Note: Main struct names capitalized for consistency So, convert userMap to UserMap.

iOS Error: Cannot convert value of type 'UserModel' to expected argument type '[String : Any]'

You have to convert your UserModel to [String : Any] type in order to save it on firebase. Try this:

func convertUserModelToDictionary(user: UserModel) -> [String : Any] {

let userData = [
"name" : user.name, // change these according to you model
"email": user.email,
"user_id": user.userId
]

return userData
}

You can use this function as:

do {
let userData = convertUserModelToDictionary(user: userInfo)
try db.collection("usersInformations").document(userInfo.id).setData(from: userData)
} catch let error {
print(error.localizedDescription)
}

Cannot convert value of type 'X' to expected argument type 'X'

Ok, I got it...

I've imported my app's module with @testable and also I've had added my .swift file with model classes to the test target. Probably <MyTestModule>. Quiz.NewRoundDetails.ViewModel have been created instead of <MyAppModule>. Quiz.NewRoundDetails.ViewModel

when i try to make a label it gives me an error - Cannot convert value of type 'String' to expected argument type 'LabelStyleConfiguration'

Maybe Something like this:

struct ContentView: View {
@State var pies = 0

var body: some View {
VStack(spacing: 30) {

Text("You have \(pies) pies")
.bold()
.shadow(color: .primary, radius: 1, x: 1, y: 1)

Button {
pieClicked()
} label: {
Label {
Text("Click the pie")
.bold()
} icon: {
Image(systemName: "chart.pie.fill")
.imageScale(.large)
.shadow(color: .primary, radius: 2, x: 2, y: 2)
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.yellow.opacity(0.4))
.foregroundColor(.orange)
.font(.title)
}

func pieClicked() { pies = pies + 1 }
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

Cannot convert value of type 'Int' to expected argument type 'string' in SwiftUI/Playgrounds

First of all please name variables with starting lowercase letter.

An URL is actually a string, even a numeric value must be a string.

So convert the integer to string explicitly.

URLQueryItem(name: "PollDuration", value: String(stepperValue))]

Cannot convert value of type '(ViewController) - () - ()' to expected argument type '() - ()'

The error is occurring because you're initialising wikipediaFetcher as a property of ViewController before it's available wikipediaFetcher. Try loading it as lazy

class ViewController: UIViewController {

private lazy var wikipediaFetcher = WikipediaFetcher(
onResponse: stopIndicationAnimation,
showResult: showResult
)

private func stopIndicationAnimation() {
// Do something
}

private func showResult(data: String) {
// Do something
}
}


Related Topics



Leave a reply



Submit