Annotated is a small library that let you annotate your strings with semantic annotations.
Once a String is annotated, you can transform it to a NSAttributedString or a SwiftUI Text
It allows you, for example, to semantically annotate a String in your View Model without thinking about the final visual style, and then render your String in your View as an NSAttributedString.
Requirements
iOS 11.0
Swift 5.1
Installation
Annotated is available through CocoaPods and SwiftPM
Example
First, you need to define your annotations. Using an enum is generally great for that.
enum AddressAnnotations: Hashable {
case city, postalCode, highlighted
}
Then you can create you Annotated<AddressAnnotations> string using a string literal. You can directly annotate parts of your string thanks to custom String Interpolation.
var string: Annotated<AddressAnnotations> = """
1 Infinite Loop
\("Cupertino", .city), CA \(95014, .postalCode)
"""
Annotated
Annotated is a small library that let you annotate your strings with semantic annotations. Once a
String
is annotated, you can transform it to aNSAttributedString
or a SwiftUIText
It allows you, for example, to semantically annotate a
String
in your View Model without thinking about the final visual style, and then render yourString
in your View as anNSAttributedString
.Requirements
Installation
Annotated is available through CocoaPods and SwiftPM
Example
First, you need to define your annotations. Using an
enum
is generally great for that.Then you can create you
Annotated<AddressAnnotations>
string using a string literal. You can directly annotate parts of your string thanks to custom String Interpolation.You can also add annotations manually.
Finally, you can render your string into an
NSAttributedString
or a SwiftUIText
using provided factory methods.Author
Jérôme Alves
License
Annotated is available under the MIT license. See the LICENSE file for more info.