Swiftpack.co - orchetect/SwiftASCII as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by orchetect.
orchetect/SwiftASCII 1.1.3
Type-safe ASCIIString and ASCIICharacter types for Swift. (ASCII string, character)
⭐️ 3
🕓 2 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/orchetect/SwiftASCII.git", from: "1.1.3")


CI Build Status Platforms - macOS | iOS | tvOS | watchOS License: MIT

Type-safe ASCIIString and ASCIICharacter types for Swift.

Complete unit test coverage.

Getting Started

Swift Package Manager (SPM)

  1. Add SwiftASCII as a dependency using Swift Package Manager.

    • In an app project or framework, in Xcode:

      • Select the menu: File → Swift Packages → Add Package Dependency...
      • Enter this URL: https://github.com/orchetect/SwiftASCII
    • In a Swift Package, add it to the Package.swift dependencies:

      .package(url: "https://github.com/orchetect/SwiftASCII", from: "1.1.0")
  2. Import the library:

    import SwiftASCII


// failable init
ASCIIString(exactly: "An ASCII String.") // succeeds
ASCIIString(exactly: "Ãñ ÂŚÇÏÎ Strïńg.") // nil

// lossy string conversion making ASCII-compatible substitutions
ASCIIString("An ASCII String.") // "An ASCII String." (unchanged)
ASCIIString("Ãñ ÂŚÇÏÎ Strïńg.") // "An ASCII String." (substituted)

// lossy string conversion through String literal type inference
let str: ASCIIString = "Ãñ ÂŚÇÏÎ Strïńg."
print(str) // "An ASCII String." (substituted)
let asciiString = ASCIIString("ÂŚÇÏÎ")

// returns typed as String
asciiString.stringValue // "ASCII"

// returns Data representation of string
asciiString.rawData // Data([0x41, 0x53, 0x43, 0x49, 0x49])


// failable init
ASCIICharacter(exactly: "A") // succeeds
ASCIICharacter(exactly: "Ω") // nil

// lossy string conversion making ASCII-compatible substitutions
ASCIICharacter("A") // "A" (unchanged)
ASCIICharacter("Ã") // "A" (substituted)

// lossy character conversion through Character literal type inference
let char: ASCIICharacter = "Ä"
print(char) // "A" (substituted)

// failable ASCII integer literal init
ASCIICharacter(65) // "A"
ASCIICharacter(300) // nil
let asciiString = ASCIICharacter("Ä")

// returns typed as Character
asciiString.characterValue // Character("A")

// returns ASCII integer literal
asciiString.asciiValue // 65

// returns Data representation of character
asciiString.rawData // Data([0x41])


Coded by a bunch of 🐹 hamsters in a trenchcoat that calls itself @orchetect.


Licensed under the MIT license. See LICENSE for details.


Contributions are welcome. Feel free to post an Issue to discuss.


Stars: 3
Last commit: 2 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

2 weeks ago
  • All initializers and extensions previously using String now allow any StringProtocol for greater flexibility.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics