I've just updated to Xcode 8 and iOS 10 (using legacy Swift Language Version).
Trying to compile again my project has been an agony, even still using the old Swift syntax. This time one of my functions uses
@dfri answer works perfectly for Swift 3.
Regarding Swift 2.3, my solution was to clean Xcode (Command+Option+Shift+K) and delete everything in
~/Library/Developer/Xcode/DerivedData. The problem doesn't disappear instantly but after some time it will stop giving that error.
Maybe it's a bug, after all we are in 8.0. I hope it gets fixed in next releases.
Thank you everyone.