19

I would like to create a character set that includes all of its own characters, as well as those from another character set. Append in other words.

I thought there'd be an obvious way, but after control-space completion in the IDE, and then poking around the docs, I couldn't fine anything.

I can see how to append all the characters from a string. But I need to append the characters from another set. I guess I could to-string the second set, if there's a to-string method.

How do I do this?

Jasper Blues
  • 28,258
  • 22
  • 102
  • 185

2 Answers2

26

You are probably seaching for this method in NSMutableCharacterSet :

- (void)formUnionWithCharacterSet:(NSCharacterSet *)otherSet

From Doc:

Modifies the receiver so it contains all characters that exist in either the receiver or otherSet.

B.S.
  • 21,660
  • 14
  • 87
  • 109
  • From what I can tell all the character sets are NSCharacterSet so they don't have access to the formUnionWithCharacterSet method. How do we combine multiple NSCharacterSets? – Luke Pighetti Sep 22 '19 at 15:45
  • @LukePighetti use mutableCopy on a NSCharacterSet: [[NSCharaterSet alphanumericCharacterSet] mutableCopy] – Stefanf Feb 17 '23 at 19:11
15

For Swift 3:

let fullCharset = aCharset.union(anotherCharset)
William Denniss
  • 16,089
  • 7
  • 81
  • 124