@@ -57,15 +57,15 @@ extension UILabel: TypographyExtensions {
5757 . paragraphStyle,
5858 value: ( paragraphStyle ?? NSParagraphStyle ( ) )
5959 . mutable
60- // .withProperty(textAlignment, for: \.alignment)
60+ // .withProperty(textAlignment, for: \.alignment)
6161 . withProperty ( lineHeight, for: \. minimumLineHeight)
6262 . withProperty ( lineHeight, for: \. maximumLineHeight)
6363 )
64- setupCache ( )
64+ setupAttributeCacheIfNeeded ( )
6565 }
6666 }
6767
68- func setupCache ( ) {
68+ func setupAttributeCacheIfNeeded ( ) {
6969 onTextChange { [ unowned self] oldText, newText in
7070
7171 // Apply cached attributes (if any) in case text have just changed from empty.
@@ -86,23 +86,23 @@ extension UILabel: TypographyExtensions {
8686 get { getAttribute ( . kern) }
8787 set {
8888 setAttribute ( . kern, value: newValue)
89- setupCache ( )
89+ setupAttributeCacheIfNeeded ( )
9090 }
9191 }
9292
9393 public var underline : NSUnderlineStyle ? {
9494 get { getAttribute ( . underlineStyle) }
9595 set {
9696 setAttribute ( . underlineStyle, value: newValue)
97- setupCache ( )
97+ setupAttributeCacheIfNeeded ( )
9898 }
9999 }
100100
101101 public var strikethrough : NSUnderlineStyle ? {
102102 get { getAttribute ( . strikethroughStyle) }
103103 set {
104104 setAttribute ( . strikethroughStyle, value: newValue)
105- setupCache ( )
105+ setupAttributeCacheIfNeeded ( )
106106 }
107107 }
108108
@@ -118,6 +118,8 @@ extension UILabel: TypographyExtensions {
118118}
119119
120120
121+ // MARK: Attributes (and caching)
122+
121123fileprivate extension NSAttributedString {
122124
123125 var entireRange : NSRange {
@@ -138,21 +140,19 @@ fileprivate extension NSAttributedString {
138140}
139141
140142
141- // MARK: Attributes
142-
143143fileprivate extension UILabel {
144144
145145 struct Keys {
146- static var placeholder : UInt8 = 0
146+ static var cache : UInt8 = 0
147147 }
148148
149149 /// An attributed string property to cache typography even when the label text is empty.
150150 var cache : NSAttributedString {
151151 get {
152- objc_getAssociatedObject ( self , & Keys. placeholder ) as? NSAttributedString ?? NSAttributedString ( string: " Placeholder " )
152+ objc_getAssociatedObject ( self , & Keys. cache ) as? NSAttributedString ?? NSAttributedString ( string: " Placeholder " )
153153 }
154154 set {
155- objc_setAssociatedObject ( self , & Keys. placeholder , newValue, . OBJC_ASSOCIATION_RETAIN_NONATOMIC)
155+ objc_setAssociatedObject ( self , & Keys. cache , newValue, . OBJC_ASSOCIATION_RETAIN_NONATOMIC)
156156 }
157157 }
158158
@@ -185,17 +185,17 @@ fileprivate extension UILabel {
185185}
186186
187187
188- extension UILabel {
188+ fileprivate extension UILabel {
189189
190190 /// Get attribute for the given key (if any).
191- fileprivate func getAttribute< AttributeType> (
191+ func getAttribute< AttributeType> (
192192 _ key: NSAttributedString . Key
193193 ) -> AttributeType ? where AttributeType: Any {
194194 return ( attributes ?? cachedAttributes) [ key] as? AttributeType
195195 }
196196
197197 /// Get `OptionSet` attribute for the given key (if any).
198- fileprivate func getAttribute< AttributeType> (
198+ func getAttribute< AttributeType> (
199199 _ key: NSAttributedString . Key
200200 ) -> AttributeType ? where AttributeType: OptionSet {
201201 if let attribute = ( attributes ?? cachedAttributes) [ key] as? AttributeType . RawValue {
@@ -206,7 +206,7 @@ extension UILabel {
206206 }
207207
208208 /// Add (or remove) attribute for the given key (if any).
209- fileprivate func setAttribute< AttributeType> (
209+ func setAttribute< AttributeType> (
210210 _ key: NSAttributedString . Key ,
211211 value: AttributeType ?
212212 ) where AttributeType: Any {
@@ -218,7 +218,7 @@ extension UILabel {
218218 }
219219
220220 /// Add (or remove) `OptionSet` attribute for the given key (if any).
221- fileprivate func setAttribute< AttributeType> (
221+ func setAttribute< AttributeType> (
222222 _ key: NSAttributedString . Key ,
223223 value: AttributeType ?
224224 ) where AttributeType: OptionSet {
@@ -231,7 +231,9 @@ extension UILabel {
231231}
232232
233233
234- extension NSParagraphStyle {
234+ // MARK: Paragraph Style
235+
236+ fileprivate extension NSParagraphStyle {
235237
236238 var mutable : NSMutableParagraphStyle {
237239 let mutable = NSMutableParagraphStyle ( )
@@ -241,7 +243,7 @@ extension NSParagraphStyle {
241243}
242244
243245
244- extension NSMutableParagraphStyle {
246+ fileprivate extension NSMutableParagraphStyle {
245247
246248 func withProperty< ValueType> (
247249 _ value: ValueType ,
0 commit comments