. Advertisement .
..3..
. Advertisement .
..4..
Hi developer experts, I have a small but frustrating use case, and so far, I couldn’t get my head around this problem & ideal solution. I am running my command, and I am facing one problem with the swift type of expression is ambiguous without more context Below is the command I used:
let imageToDeleteParameters = imagesToDelete.map { ["id": $0.id, "url": $0.url.absoluteString, "_destroy": true] }
extension TutorialCreationRequest: WebserviceParametrable {
func toParameters() -> [String: AnyObject] {
let imageParameters = images.map { ["url": $0] }
let imageToDeleteParameters = imagesToDelete.map { ["id": $0.id, "url": $0.url.absoluteString, "_destroy": true] }
return [
"title": title,
"is_draft": isDraft,
"difficulty": difficulty,
"duration": duration,
"cost": cost,
"user_id": userId,
"description": description,
"to_sell": toSell,
"images": [imageParameters, imageToDeleteParameters].flatMap { $0 }
]
}
}
When I run it, I get the following error:
Type of expression is ambiguous without more context
I am looking forward to gaining some knowledge from all experts. Thank you, guys!
The cause: The reason is that you you changed the name of a Variable and did not refactor when doing that. Solution: It will work if you declare clearly the inputs and then mapping task do the following way:
Replace the real class of “$0” for “WhateverClass” in that code snippet. Fixed code:
This is when you have an argument name that is not correct for a function.
Example:
And You declared your function as
This happens most often when you change the name of a Variable. When you do this, make sure to refactor.