I am trying to convert over swift 2 code to swift 3:
var customAllowedSet = NSCharacterSet(charactersInString:"=\"#%/<>?@\\^`{|}").invertedSet
It throws this error:
Value of type CharacterSet has no member InvertedSet
I am trying to convert over swift 2 code to swift 3:
var customAllowedSet = NSCharacterSet(charactersInString:"=\"#%/<>?@\\^`{|}").invertedSet
It throws this error:
Value of type CharacterSet has no member InvertedSet
In Swift 3 you are also supposed to drop the NS prefix. You should use CharacterSet instead of NSCharacterSet. You should also declare it as a constant.
let customAllowedSet = CharacterSet(charactersIn: "=\"#%/<>?@\\^`{|}").inverted
You can also declare it as a static property extending CharacterSet as follow:
extension CharacterSet {
static let customAllowedSet = CharacterSet(charactersIn:"=\"#%/<>?@\\^`{|}").inverted
}
CharacterSet.customAllowedSet
According to Apple documentation the name of
invertedSet
method in Swift 3 was changed to justinverted
. So try this:PS:
init(charactersInString:)
ofCharacterSet
also changed toinit(charactersIn:)