Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 2.01 KB

File metadata and controls

47 lines (32 loc) · 2.01 KB

TLDManager

When working with URLs, you often need to check the correctness of specified top-level domains. However, keeping a separate list of TLDs in each Swift project is error-prone and difficult to maintain. TLDManager is designed to solve this problem as an easy to import Swift Package.

This Swift Package is used in production by URL Detector for Safari.

Installation

TLDManager is currently only available via Swift Package Manager (SPM). It is not planned to implement support for CocoaPods or Carthage – but feel free to make a pull request.

// Add TLDManager to your Package.swift:

import PackageDescription

let package = Package(
    // ...
    dependencies: [
        .package(url: "https://github.com/Suboptimierer/TLDManager", from: "1.1.0"),
    ]
    // ...
)

Xcode >= 11: FileSwift PackagesAdd Package Dependency...

Xcode >= 13: FileAdd Packages... / ProjectPackage Dependencies

For more information check the Apple Developer Documentation.

Usage

// Import the TLDManager module
import TLDManager

// Access the static properties...
let _ = TLDManager.version                          // # Version 2022070600, Last Updated Wed Jul  6 07:07:01 2022 UTC
let _ = TLDManager.allValidTLDsUppercased           // ["AAA", "AARP", "ABARTH", "ABB", "ABBOTT", "ABBVIE", "ABC", ...]
let _ = TLDManager.allValidTLDsUppercasedWithDots   // [".AAA", ".AARP", ".ABARTH", ".ABB", ".ABBOTT", ".ABBVIE", ".ABC", ...]
let _ = TLDManager.allValidTLDsLowercased           // ["aaa", "aarp", "abarth", "abb", "abbott", "abbvie", "abc", ...]
let _ = TLDManager.allValidTLDsLowercasedWithDots   // [".aaa", ".aarp", ".abarth", ".abb", ".abbott", ".abbvie", ".abc", ...]

Source

The list of all valid top-level domains is maintained by the IANA and is updated from time to time.