TomTomCopyrightsService

final public class TomTomCopyrightsService : CopyrightsService

Default implementation of CopyrightsService.

  • Creates a TomTomCopyrightsService instance.

    Declaration

    Swift

    public convenience init()
  • fetchCopyrights() Asynchronous

    Get copyright details.

    For users who are utilizing iOS 15+ and leveraging SwiftUI to ensure accurate rendering of hyperlinks that are interactive (tappable) and capable of opening in the web browser, the following method can be employed:

    func parseContent(_ content: String) -> AttributedString {
        do {
            let detector = try NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
            let matches = detector.matches(in: content, options: [], range: NSRange(location: 0, length: content.utf16.count))
    
            let modifiedContent = NSMutableAttributedString(string: content)
    
            for match in matches.reversed() {
                guard let range = Range(match.range, in: content) else { continue }
                let url = content[range]
                let markdownLink = "[\(url)](\(url))"
                let markdownAttributedString = try AttributedString(markdown: markdownLink)
                modifiedContent.replaceCharacters(in: match.range, with: NSAttributedString(markdownAttributedString))
            }
    
            return AttributedString(modifiedContent)
        } catch {
            return AttributedString("Something went wrong during the Copyright parsing.")
        }
    }
    

    Example of usage of this method:

    Text(parseContent(text))
    

    Important

    This is a Public Preview API. It may be changed or removed at any time.

    Declaration

    Swift

    public func fetchCopyrights() async -> String?

    Return Value

    String copyright details in HTML format

  • Get copyright details.

    For users who are utilizing iOS 15+ and leveraging SwiftUI to ensure accurate rendering of hyperlinks that are interactive (tappable) and capable of opening in the web browser, the following method can be employed:

    func parseContent(_ content: String) -> AttributedString {
        do {
            let detector = try NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
            let matches = detector.matches(in: content, options: [], range: NSRange(location: 0, length: content.utf16.count))
    
            let modifiedContent = NSMutableAttributedString(string: content)
    
            for match in matches.reversed() {
                guard let range = Range(match.range, in: content) else { continue }
                let url = content[range]
                let markdownLink = "[\(url)](\(url))"
                let markdownAttributedString = try AttributedString(markdown: markdownLink)
                modifiedContent.replaceCharacters(in: match.range, with: NSAttributedString(markdownAttributedString))
            }
    
            return AttributedString(modifiedContent)
        } catch {
            return AttributedString("Something went wrong during the Copyright parsing.")
        }
    }
    

    Example of usage of this method:

    Text(parseContent(text))
    

    Declaration

    Swift

    public func fetchCopyrights(completion: @escaping (String?) -> ())

    Parameters

    completion

    Completion handler for when we get the copyrights.