Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Domain Parser

Platforms License Carthage compatible Swift Package Manager compatible

A full-Swift simple library which allows the parsing of hostnames, using the Public Suffix List.

This Library allows finding the domain name and the public suffix / top-level-domain for a given URL.

What is the Public Suffix List ?

The PSL lists all the known public suffixes (like: com,,, ...). Without this information we are not able to determine which part of a URL is the domain, since a suffix can have more than one Label. A suffix rule may also contain wildcards or exceptions to wildcards. If you want to understand the full format of PSL matching rules, you can read their specification here.

The PSL is continuously updated.

The list includes ICANN suffixes (official top level domains) but also private suffixes (like


URL host Domain Public suffix Matched PSL rule Explanation com com Simple rule Simple rule *.ck Wildcard rule *.ck Wildcard rule *.ck Wildcard rule ck ! Exception rule ck ! Exception rule ck ! Exception rule



import DomainParser
let domainParser = try DomainParser()

You should use the same instance when you parse multiple URL hosts.

let domain: String? = domainParser.parse(host: "")?.domain
print(domain ?? "N/A") //
let suffix1: String? = domainParser.parse(host: "")?.publicSuffix
print(suffix1 ?? "N/A") // com

let suffix2: String? = domainParser.parse(host: "")?.publicSuffix
print(suffix2 ?? "N/A") //

Update the local Public Suffix List

The local PSL used by the library is located at DomainParser/DomainParser/Resources/public_suffix_list.dat.

To update it, run this Terminal command in the script folder:

swift UpdatePSL.swift