ixany ixany - 1 year ago 204
Swift Question

How to create a custom NSCharacterSet?

I'm using

to add percent-encoding on a string, however, it seems to be blind for some chars, i.e. "&" or "?". How can I build a custom NSCharacterSet based on the existing one?

Answer Source

The most typical way to create a new character set is using + characterSetWithCharactersInString, giving a NSString with all the characters of the set.

Adding some characters to an existing set can be achieved using:

let characterSet = NSMutableCharacterSet() //create an empty mutable set

For URL encoding, also note Objective-C url encoding

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download