3

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
Tim Nuwin
  • 2,775
  • 2
  • 29
  • 63

2 Answers2

6

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:)

ninjaproger
  • 2,024
  • 1
  • 27
  • 26
2

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
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571