Skip to content

Repository files navigation

Swift Package Manager compatible Carthage compatible Cocoapods Version Cocoapods Platform Build codecov Language License

PunycodeSwift

PunycodeSwift is a pure Swift library to allows you to encode and decode punycoded strings by using String extension.

What is Punycode?

Punycode is a representation of Unicode with the limited ASCII character subset used for Internet host names. Using Punycode, host names containing Unicode characters are transcoded to a subset of ASCII consisting of letters, digits, and hyphen, which is called the Letter-Digit-Hyphen (LDH) subset. For example, München (German name for Munich) is encoded as Mnchen-3ya. (Wikipedia)

Requirements

  • macOS 10.13 or later
  • iOS 12.0 or later
  • tvOS 12.0 or later
  • watchOS 4.0 or later
  • visionOS 1.0 or later
  • Swift 5.0 or later

Installation

Swift Package Manager is the recommended way to install PunycodeSwift.

Important

The CocoaPods trunk becomes permanently read-only on December 2, 2026. Versions released after that date will be available via Swift Package Manager (and Carthage on a best-effort basis) only. If you are using CocoaPods, please migrate to Swift Package Manager.

Swift Package Manager

Add the following to your Package.swift file.

  • macOS, iOS, tvOS, watchOS, visionOS, and Swift 5

    dependencies: [
        .package(url: "https://github.com/futamura/PunycodeSwift.git", .upToNextMajor(from: "3.0.0"))
    ]
  • macOS, iOS, tvOS, and Swift 5

    dependencies: [
        .package(url: "https://github.com/futamura/PunycodeSwift.git", .upToNextMajor(from: "2.1.1"))
    ]

Carthage

Note

Carthage itself is in maintenance mode. Carthage compatibility is kept on a best-effort basis and is no longer verified by CI.

Add the following to your Cartfile and follow these instructions.

  • macOS, iOS, tvOS, watchOS, visionOS, and Swift 5

    github "futamura/PunycodeSwift" ~> 3.0
    
  • macOS, iOS, tvOS, and Swift 5

    github "futamura/PunycodeSwift" ~> 2.0
    
  • macOS, iOS, tvOS, and Swift 4

    github "futamura/PunycodeSwift" ~> 1.0
    

CocoaPods

Warning

CocoaPods distribution ends when the trunk becomes read-only on December 2, 2026. Existing versions will remain installable, but no new versions will be published. Please migrate to Swift Package Manager.

To integrate PunycodeSwift into your project, add the following to your Podfile.

  • macOS, iOS, tvOS, watchOS, visionOS, and Swift 5.0

    pod 'Punycode', '~> 3.0'
  • macOS, iOS, tvOS, and Swift 5.0

    pod 'Punycode', '~> 2.0'
  • macOS, iOS, tvOS, and Swift 4.2

    pod 'Punycode', '~> 1.0'

Usage

Full documentation is available at https://futamura.github.io/PunycodeSwift/documentation/punycode/.

Encode and decode IDNA:

import Punycode

var sushi: String = "寿司"

sushi = sushi.idnaEncoded!
print(sushi)  // xn--sprr0q

sushi = sushi.idnaDecoded!
print(sushi)  // "寿司"

Encode and decode Punycode directly:

import Punycode

var sushi: String = "寿司"

sushi = sushi.punycodeEncoded!
print(sushi)  // sprr0q

sushi = sushi.punycodeDecoded!
print(sushi)  // "寿司"

Copyright

Punycode is released under MIT license, which means you can modify it, redistribute it or use it however you like.

About

PunycodeSwift is a pure Swift library to allows you to encode and decode punycoded strings

Topics

Resources

Contributing

Security policy

Stars

33 stars

Watchers

3 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages