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
More Precision Than Double in Swift
Nsjsonserialization Error. Code=3840 "Invalid Value Around Character 0
Why Would One Use Nested Classes
Swift Increment Int! Not Working
How to Create a Pulse Effect on an Skspritenode
Difference When Declaring Swift Protocol Using Inheritance from Another Protocol or Using Where Self
How to Add Two Generic Values in Swift
Swift: Using Member Constant as Default Value for Function Parameter
How to Keep a User Logged In? Swift
Firebase Connection State Always Returning False on First Run
Xcode Error: Ar Reference Image Must Have Non Zero Positive Width
Why Does Cabasicanimation Try to Initialize Another Instance of My Custom Calayer
How to Test If an Instance Is a Specific Class or Type in Swift
Xcode 7 Cast from Xcuielement to Unrelated Type 'string' Always Fails While Fetching JSON
Crash Casting Wknsurlrequest As? Other Type
Negative Arrayslice: Index Is Out of Range
How to Mirror The Design of The Codable/Codablekeys Protocols
Navigationlink Doesn't Work with New .Searchable Modifier on Swiftui 3.0