I have my custom attribute here, just for testing, the goal is to swap letters just to see how I can affect the string
enum SwapAttribute : AttributedStringKey {
typealias Value = String
static let name = "swap"
}
extension AttributeScopes {
struct MyTextStyleAttributes: AttributeScope {
let swap: SwapAttribute
}
}
extension AttributeDynamicLookup {
subscript<T: AttributedStringKey>(dynamicMember keyPath: KeyPath<AttributeScopes.MyTextStyleAttributes, T>) -> T {
return self[T.self]
}
}
func attributesTest() {
var str = AttributedString("It's a secret")
let secret = str.range(of: "secret")!
str[secret].swap = "*"
// expect 'It's a ******'
print(str)
}
I can add my attribute, and I can see it in the .runs variable, but all of the documentation and tutorials gloss over this. How do I execute code or apply changes to the string.
(or perhaps this is intended for other things)