> extension Character {
> 
>   func isMemberOfSet( set:NSCharacterSet )
>     -> Bool
>   {
>     // The for loop only executes once;
>     // its purpose is to convert Character to a type
>     // you can actually do something with
>     for char in String( self ).utf16 {
>       if set.characterIsMember( char ) {
>         return true
>       }
>     }
>     return false
>   }
> 
> }

I believe your comment that the loop executes once is incorrect.   It may
execute more than once when the Character is a composed character that
maps to multiple utf16 characters.

Example (stolen from this link):
  
http://stackoverflow.com/questions/27697508/nscharacterset-characterismember-with-swifts-character-type


let acuteA: Character = "\u{e1}"                   // An "a" with an accent
let acuteAComposed: Character = "\u{61}\u{301}"    // Also an "a" with an accent

Both are a single Character.  The latter will cause the loop to iterate twice.

Marc
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to