Closed scalessec closed 6 years ago
Interesting, I've never considered custom string keys. I like the idea of a .custom
attribute, although I feel like .custom(String, Any)
would make more sense to ensure a one-to-one mapping of attribute to Attribute
. Started working on it already!
@scalessec Just opened #26, feel free to give feedback!
Fixed in v4.2.0! Thanks for calling this out.
When working with
NSAttributedStrings
that use customNSAttributedStringKey
values, SwiftyAttributes crashes whenever attributes are accessed.Here's one way to reproduce:
I realize that type-safety for a finite number of
Foundation
values is part of SwiftyAttributes's appeal, but I also think this crash should be handled by the library due to the existence ofNSAttributedStringKey(string:)
.I haven't given too much thought into how I think this could be handled, but perhaps something like:
.custom([String: Any])
is an appropriate solution for anyNSAttributedStringKey
values that can't be constructed viaNSAttributedStringKey(rawValue:)
.FWIW, this came up due to some work I'm doing with markdown rendering, where we're storing the URL for links in a custom attribute as part of the attributed string.