MapCopyrights
final public class MapCopyrights
Provides methods to fetch copyrights and caption.
Important
This is a Public Preview API. It may be changed or removed at any time.
fetchCaption()
Asynchronous
Fetches copyrights caption.
Throws
An error occurred during the retrieval process.Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func fetchCaption() async throws -> String
Return Value
String copyrights caption in HTML format.
Fetches copyrights caption.
Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
@discardableResult
public func fetchCaption(completion: @escaping (Result<String, Error>) -> ()) -> Cancellable
Parameters
completion
|
Completion handler that is called to receive the copyrights. If no errors occurred, string contain caption. |
Return Value
A Cancellable
for the network request operation.
fetchCopyrights()
Asynchronous
Fetches 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))
Throws
An error occurred during the retrieval process.Important
This is a Public Preview API. It may be changed or removed at any time.Declaration
Swift
public func fetchCopyrights() async throws -> String
Return Value
String copyright details in HTML format.
Fetches 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
@discardableResult
public func fetchCopyrights(completion: @escaping (Result<String, Error>) -> ()) -> Cancellable
Parameters
completion
|
Completion handler that is called to receive the copyrights. If no errors occurred, string contain caption. |
Return Value
A Cancellable
for the network request operation.
Creates a MapCopyrights
instance.
Declaration
Swift
public convenience init()