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
According to Apple documentation the name of invertedSet
method in Swift 3 was changed to just inverted
. So try this:
var customAllowedSet = CharacterSet(charactersIn:"=\"#%/<>?@\\^`{|}").inverted
PS: init(charactersInString:)
of CharacterSet
also changed to init(charactersIn:)
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