### Carthage Configuration Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/index.html Add these lines to your Cartfile to integrate the library via Carthage. ```text github "gumob/TLDExtractSwift" ~> 3.0 ``` ```text github "gumob/TLDExtractSwift" ~> 2.0 ``` ```text github "gumob/TLDExtractSwift" ~> 1.0 ``` -------------------------------- ### parse(_:quick:) Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Classes/TLDExtract.html Parses a given hostname to extract its TLD components. ```APIDOC ## parse(_:quick:) ### Description Extracts the top-level domain from the provided input. ### Parameters - **input** (T: TLDExtractable) - Required - The hostname to be parsed. - **quick** (Bool) - Optional - If true, parses only normal data, excluding exceptions and wildcards. Defaults to false. ### Returns - **TLDResult?** - The extracted TLD information or nil if parsing fails. ``` -------------------------------- ### init(useFrozenData:) Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Classes/TLDExtract.html Initializes a new instance of the TLDExtract class. Allows specifying whether to use a pre-fetched frozen dataset or fetch the public suffix list remotely. ```APIDOC ## init(useFrozenData:) ### Description Initializes the TLDExtract instance. Throws a TLDExtractError.pslParseError if the public suffix list cannot be parsed. ### Parameters - **useFrozenData** (Bool) - Optional - A Boolean value indicating whether to use a pre-fetched public suffix list. Defaults to false. ``` -------------------------------- ### Extract from String Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/index.html Parse URLs or hostnames provided as strings to retrieve domain components. ```swift let urlString: String = "https://www.github.com/gumob/TLDExtract" guard let result: TLDResult = extractor.parse(urlString) else { return } print(result.rootDomain) // Optional("github.com") print(result.topLevelDomain) // Optional("com") print(result.secondLevelDomain) // Optional("github") print(result.subDomain) // Optional("www") ``` ```swift let hostname: String = "gumob.com" guard let result: TLDResult = extractor.parse(hostname) else { return } print(result.rootDomain) // Optional("gumob.com") print(result.topLevelDomain) // Optional("com") print(result.secondLevelDomain) // Optional("gumob") print(result.subDomain) // nil ``` ```swift let hostname: String = "www.ラーメン.寿司.co.jp" guard let result: TLDResult = extractor.parse(hostname) else { return } print(result.rootDomain) // Optional("寿司.co.jp") print(result.topLevelDomain) // Optional("co.jp") print(result.secondLevelDomain) // Optional("寿司") print(result.subDomain) // Optional("www.ラーメン") ``` ```swift let hostname: String = "www.xn--4dkp5a8a.xn--sprr0q.co.jp")" guard let result: TLDResult = extractor.parse(hostname) else { return } print(result.rootDomain) // Optional("xn--sprr0q.co.jp") print(result.topLevelDomain) // Optional("co.jp") print(result.secondLevelDomain) // Optional("xn--sprr0q") print(result.subDomain) // Optional("www.xn--4dkp5a8a") ``` -------------------------------- ### Initialize TLDExtract Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Classes/TLDExtract.html Initializes the extractor with an option to use frozen data instead of fetching a remote list. ```Swift public init(useFrozenData: Bool = false) throws ``` -------------------------------- ### Parse Hostname Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Classes/TLDExtract.html Extracts TLD information from a given host, with an optional quick mode to skip exceptions and wildcards. ```Swift public func parse(_ input: T, quick: Bool = false) -> TLDResult? where T : TLDExtractable ``` -------------------------------- ### CocoaPods Integration Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/index.html Add these lines to your Podfile to integrate the library via CocoaPods. ```ruby pod 'TLDExtractSwift', '~> 3.0' ``` ```ruby pod 'TLDExtract', '~> 2.0' ``` ```ruby pod 'TLDExtract', '~> 1.0' ``` -------------------------------- ### hostname Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Extensions/URL.html Retrieves the hostname from a URL instance. ```APIDOC ## public var hostname: String? ### Description Returns the hostname extracted from the URL instance. ### Declaration `public var hostname: String? { get }` ### Return Value A `String` representing the hostname, or `nil` if the hostname cannot be extracted. ``` -------------------------------- ### var hostname: String? Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Extensions/String.html Extracts the hostname from a string, handling both URLs and plain domain names. ```APIDOC ## var hostname: String? ### Description Returns the hostname extracted from the string. This property uses regular expressions to identify the hostname, accounting for schemes like http:// or https://. ### Declaration `public var hostname: String? { get }` ### Return Value - **String?** - The extracted hostname, or nil if extraction fails. ``` -------------------------------- ### Swift Package Manager Dependencies Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/index.html Add these dependencies to your Package.swift file based on your target platform and Swift version requirements. ```swift dependencies: [ .package(url: "https://github.com/gumob/TLDExtractSwift.git", .upToNextMajor(from: "3.0.0")) ] ``` ```swift dependencies: [ .package(url: "https://github.com/gumob/TLDExtractSwift.git", .upToNextMajor(from: "2.1.1")) ] ``` -------------------------------- ### Declare Hostname Property Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Protocols/TLDExtractable.html The required property declaration for conforming types to return an optional hostname string. ```Swift var hostname: String? { get } ``` -------------------------------- ### Extract from Foundation URL Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/index.html Parse Foundation URL objects, including workarounds for unicode support. ```swift let urlString: String = "http://www.ラーメン.寿司.co.jp" let url: URL = URL(unicodeString: urlString) guard let result: TLDResult = extractor.parse(url) else { return } print(result.rootDomain) // Optional("www.ラーメン.寿司.co.jp") print(result.topLevelDomain) // Optional("co.jp") print(result.secondLevelDomain) // Optional("寿司") print(result.subDomain) // Optional("www.ラーメン") ``` ```swift let urlString: String = "http://www.ラーメン.寿司.co.jp".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! let url: URL = URL(string: urlString) print(urlString) // http://www.%E3%83%A9%E3%83%BC%E3%83%A1%E3%83%B3.%E5%AF%BF%E5%8F%B8.co.jp guard let result: TLDResult = extractor.parse(url) else { return } print(result.rootDomain) // Optional("www.ラーメン.寿司.co.jp") print(result.topLevelDomain) // Optional("co.jp") print(result.secondLevelDomain) // Optional("寿司") print(result.subDomain) // Optional("www.ラーメン") ``` ```swift import Punycode let urlString: String = "http://www.ラーメン.寿司.co.jp".idnaEncoded! let url: URL = URL(string: urlString) print(urlString) // http://www.xn--4dkp5a8a.xn--sprr0q.co.jp guard let result: TLDResult = extractor.parse(url) else { return } print(result.rootDomain) // Optional("xn--sprr0q.co.jp") print(result.topLevelDomain) // Optional("co.jp") print(result.secondLevelDomain) // Optional("xn--sprr0q") print(result.subDomain) // Optional("www.xn--4dkp5a8a") ``` -------------------------------- ### Conform URL to TLDExtractable Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Extensions/URL.html Declares the conformance of the URL type to the TLDExtractable protocol. ```Swift extension URL: TLDExtractable ``` -------------------------------- ### String TLDExtractable Extension Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Extensions.html Conforms the String type to the TLDExtractable protocol for hostname extraction. ```Swift extension String: TLDExtractable ``` -------------------------------- ### TLDResult Property Declarations Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Structs/TLDResult.html Individual property declarations for the components of a domain name. ```Swift public let rootDomain: String? ``` ```Swift public let topLevelDomain: String? ``` ```Swift public let secondLevelDomain: String? ``` ```Swift public let subDomain: String? ``` -------------------------------- ### Extract hostname from URL Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Extensions/URL.html Accesses the hostname property of a URL, returning a string or nil if extraction fails. ```Swift public var hostname: String? { get } ``` -------------------------------- ### TLDExtract Class Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Classes.html The TLDExtract class is the primary interface for extracting TLDs from hostnames. It can be initialized to use either a remote public suffix list or a frozen dataset. ```APIDOC ## TLDExtract ### Description TLDExtract is a class that extracts the top-level domain (TLD) from a given hostname. It can fetch the public suffix list from a remote source or use a frozen dataset. ### Declaration `public class TLDExtract` ### Parameters - **useFrozenData** (Boolean) - A Boolean value indicating whether to use a pre-fetched public suffix list. ### Errors - **TLDExtractError.pslParseError**: Thrown if there is an error while parsing the public suffix list. ``` -------------------------------- ### Update Import Statement Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/index.html Update your source code imports to reflect the library name change in version 3.0.0. ```swift - import TLDExtract + import TLDExtractSwift ``` -------------------------------- ### Define TLDExtractable Protocol Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Protocols/TLDExtractable.html The base protocol definition requiring types to provide a hostname. ```Swift public protocol TLDExtractable ``` -------------------------------- ### TLDResult Structure Declaration Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Structs/TLDResult.html The primary structure definition for TLD extraction results. ```Swift public struct TLDResult ``` -------------------------------- ### TLDExtract Class Definition Source: https://gumob.github.io/TLDExtractSwift/swiftdoc/Classes/TLDExtract.html The primary class for TLD extraction operations. ```Swift public class TLDExtract ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.