The following code throws the following error: "Value of type string has no member componentsSeparatedByCharactersInSet"
This code is from another project that worked before in swift versions 1 or 2 but no longer works.
import Foundation
extension String {
func split() -> [String] {
return self.componentsSeparatedByCharactersInSet(
CharacterSet.whitespaceAndNewlineCharacterSet())
.filter({$0 != ""});
}
}
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;
}
}
You're looking for
components(separatedBy:)
: