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.
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: File
→ Swift Packages
→ Add Package Dependency...
Xcode >= 13: File
→ Add Packages...
/ Project
→ Package Dependencies
For more information check the Apple Developer Documentation.
// 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", ...]
The list of all valid top-level domains is maintained by the IANA and is updated from time to time.