I am trying to reduce an array of objects to a set in Swift and this is my code:
objects.reduce(Set<String>()) { $0.insert($1.URL) }
However, I get an error:
Type of expression is ambiguous without more context.
I do not understand what the problem is, since the type of URL is definitely String. Any ideas?
You don't have to reduce an array to get it into a set; just create the set with an array: let objectSet = Set(objects.map { $0.URL })
.