I tried converting my project to Swift 4 this day. I'm having an error on this line:
return Forum.threads?.filter({ //... })
The error says:
Ambiguous use of 'filter'
Found this candidate (Swift.Set)
Found this candidate (Swift.Sequence)
threads
object is implemented like this in Forum
:
var threads: Set<Thread>?
So how to solve this..? Thanks for your help
EDIT : when revealing the error in log, here are the candidates:
Swift.Set:369:17: note: found this candidate
public func filter(_ isIncluded: (Set.Element) throws -> Bool) rethrows -> Set<Element>
^
Swift.Sequence:35:17: note: found this candidate
public func filter(_ isIncluded: (Self.Element) throws -> Bool) rethrows -> [Self.Element]
To solve this, declare the type of the variable before you return it.
let x: [Character] = input.filter{/**/}
return x
This disambiguates the return type of the filter{} method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With