How to use stringByAddingPercentEncodingWithAllowedCharacters() for a URL in Swift 2.0

For the given URL string the equivalent to let urlwithPercentEscapes = myurlstring.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) is the character set URLQueryAllowedCharacterSet let urlwithPercentEscapes = myurlstring.stringByAddingPercentEncodingWithAllowedCharacters( NSCharacterSet.URLQueryAllowedCharacterSet()) Swift 3: let urlwithPercentEscapes = myurlstring.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed) It encodes everything after the question mark in the URL string. Since the method stringByAddingPercentEncodingWithAllowedCharacters can return nil, use optional bindings as suggested in the … Read more

NSArray from NSCharacterSet

The following code creates an array containing all characters of a given character set. It works also for characters outside of the “basic multilingual plane” (characters > U+FFFF, e.g. U+10400 DESERET CAPITAL LETTER LONG I). NSCharacterSet *charset = [NSCharacterSet uppercaseLetterCharacterSet]; NSMutableArray *array = [NSMutableArray array]; for (int plane = 0; plane <= 16; plane++) { … Read more