mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-26 19:34:25 +02:00
Setup NSTextAttachmentViewProvider
This commit is contained in:
@@ -24,4 +24,24 @@ public extension NSAttributedString {
|
||||
result.removeAttribute(.link, range: NSRange(location: 0, length: length))
|
||||
return result
|
||||
}
|
||||
|
||||
/// Enumerate attribute for given key and conveniently ignore any attribute that doesn't match given generic type.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - attrName: The name of the attribute to enumerate.
|
||||
/// - enumerationRange: The range over which the attribute values are enumerated.
|
||||
/// - opts: The options used by the enumeration. For possible values, see NSAttributedStringEnumerationOptions.
|
||||
/// - block: The block to apply to ranges of the specified attribute in the attributed string.
|
||||
func vc_enumerateAttribute<T>(_ attrName: NSAttributedString.Key,
|
||||
in enumerationRange: NSRange,
|
||||
options opts: NSAttributedString.EnumerationOptions = [],
|
||||
using block: (T, NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
|
||||
self.enumerateAttribute(attrName,
|
||||
in: enumerationRange,
|
||||
options: opts) { (attr: Any?, range: NSRange, stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
guard let typedAttr = attr as? T else { return }
|
||||
|
||||
block(typedAttr, range, stop)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user