user6510422 user6510422 - 5 months ago 27
iOS Question

Error: Extra argument in call

After using this code from a tutorial that apparently worked before, isn't working now using swift 3 but I'm not sure why. The error shows on the line: if !contains(uniqueValues, value as T)

extension Array {

func unique<T: Equatable>() -> [T] {
var uniqueValues = [T]();

for value in self {
if !contains(uniqueValues, value as T) {
uniqueValues.append(value as! T);
}
}
return uniqueValues;
}

func first<T>(test:(T) -> Bool) -> T? {
for value in self {
if test(value as! T) {
return value as? T;
}
}
return nil;
}
}

Answer

Since Swift 2, contains(_:) has been refactored into an instance method on Array:

if uniqueValues.contains(value as T)