Simple Cocoa methods for Punycode and IDNA on NSString
C C++ Objective-C Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Punycode Cocoa

Build Status

v1.4 (2018) by Nate Weaver (Wevah)

A simple punycode/IDNA category on NSString, based on code and documentation from RFC 3492 and RFC 3490.

Use this to convert internationalized domain names (IDN) between Unicode and ASCII.

To use in your own projects, all you need is NSStringPunycodeAdditions.h/m. This project includes a sample testing app.


Define PUNYCODE_COCOA_USE_WEBKIT to have Punycode Cocoa methods call internal WebKit methods instead of the custom implementations. Useful if you're already linking against WebKit, or want additional homograph attack protection. However, this probably won't be allowed on the App Store due to its use of private methods.

Define PUNYCODE_COCOA_USE_ICU to use ICU (by default the system's ICU).



@property (readonly, copy, nullable)	NSString *punycodeEncodedString;
@property (readonly, copy, nullable)	NSString *punycodeDecodedString;

Encodes or decodes a string to its punycode-encoded format, stripping variation selectors (U+FE00U+FE0F).

@property (readonly, copy, nullable) NSString *IDNAEncodedString;

If self contains non-ASCII, calls -punycodeEncodedString and prepends xn--.

@property (readonly, copy, nullable) NSString *IDNADecodedString;

Decodes a string returned by -IDNAEncodedString.

@property (readonly, copy, nullable) NSString *encodedURLString;
@property (readonly, copy, nullable) NSString *decodedURLString;

Performs encode/decode operations on each appropriate part (the domain bits) of an URL string.


+ (nullable instancetype)URLWithUnicodeString:(NSString *)URLString;

Convenience method equivalent to [NSURL URLWithString:URLString.encodedURLString].

@property (readonly, copy, nullable) NSString *decodedURLString;

Convenience property equivalent to anURL.absoluteString.decodedURLString.

© 2012–2017 Nate Weaver (Wevah)