@@ -50,11 +50,11 @@ public class Style: StyleProtocol {
5050
5151 /// Attributes defined by the style. This is the dictionary modified when you
5252 /// set a style attributed.
53- private var innerAttributes : [ NSAttributedStringKey : Any ] = [ : ]
53+ private var innerAttributes : [ NSAttributedString . Key : Any ] = [ : ]
5454
5555 /// This is a cache array used to avoid the evaluation of font description and other
5656 /// sensitive data. Cache is invalidated automatically when needed.
57- private var cachedAttributes : [ NSAttributedStringKey : Any ] ? = nil
57+ private var cachedAttributes : [ NSAttributedString . Key : Any ] ? = nil
5858
5959 //MARK: - PROPERTIES
6060
@@ -347,14 +347,14 @@ public class Style: StyleProtocol {
347347
348348 /// Enable spoken of all punctuation in the text.
349349 public var speaksPunctuation : Bool ? {
350- set { self . set ( attribute: newValue, forKey: NSAttributedStringKey ( UIAccessibilitySpeechAttributePunctuation ) ) }
351- get { return self . get ( attributeForKey: NSAttributedStringKey ( UIAccessibilitySpeechAttributePunctuation ) ) }
350+ set { self . set ( attribute: newValue, forKey: NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechPunctuation ) ) ) }
351+ get { return self . get ( attributeForKey: NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechPunctuation ) ) ) }
352352 }
353353
354354 /// The language to use when speaking a string (value is a BCP 47 language code string).
355355 public var speakingLanguage : String ? {
356- set { self . set ( attribute: newValue, forKey: NSAttributedStringKey ( UIAccessibilitySpeechAttributeLanguage ) ) }
357- get { return self . get ( attributeForKey: NSAttributedStringKey ( UIAccessibilitySpeechAttributeLanguage ) ) }
356+ set { self . set ( attribute: newValue, forKey: NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechLanguage ) ) ) }
357+ get { return self . get ( attributeForKey: NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechLanguage ) ) ) }
358358 }
359359
360360 /// Pitch to apply to spoken content. Value must be in range range 0.0 to 2.0.
@@ -364,16 +364,16 @@ public class Style: StyleProtocol {
364364 ///
365365 /// The default value for this attribute is 1.0, which indicates a normal pitch.
366366 public var speakingPitch : Double ? {
367- set { self . set ( attribute: newValue, forKey: NSAttributedStringKey ( UIAccessibilitySpeechAttributePitch ) ) }
368- get { return self . get ( attributeForKey: NSAttributedStringKey ( UIAccessibilitySpeechAttributePitch ) ) }
367+ set { self . set ( attribute: newValue, forKey: NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechPitch ) ) ) }
368+ get { return self . get ( attributeForKey: NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechPitch ) ) ) }
369369 }
370370
371371 /// No overview available.
372372 /// Note: available only from iOS 11, tvOS 11 and watchOS 4.
373373 @available ( iOS 11 . 0 , tvOS 11 . 0 , iOSApplicationExtension 11 . 0 , watchOS 4 , * )
374374 public var speakingPronunciation : String ? {
375- set { self . set ( attribute: newValue, forKey: NSAttributedStringKey ( UIAccessibilitySpeechAttributeIPANotation ) ) }
376- get { return self . get ( attributeForKey: NSAttributedStringKey ( UIAccessibilitySpeechAttributeIPANotation ) ) }
375+ set { self . set ( attribute: newValue, forKey: NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechIPANotation ) ) ) }
376+ get { return self . get ( attributeForKey: NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechIPANotation ) ) ) }
377377 }
378378
379379 /// Spoken text is queued behind, or interrupts, existing spoken content.
@@ -384,15 +384,15 @@ public class Style: StyleProtocol {
384384 @available ( iOS 11 . 0 , tvOS 11 . 0 , iOSApplicationExtension 11 . 0 , watchOS 4 , * )
385385 public var shouldQueueSpeechAnnouncement : Bool ? {
386386 set {
387- let key = NSAttributedStringKey ( UIAccessibilitySpeechAttributeQueueAnnouncement )
387+ let key = NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechQueueAnnouncement ) )
388388 guard let v = newValue else {
389389 self . innerAttributes. removeValue ( forKey: key)
390390 return
391391 }
392392 self . set ( attribute: NSNumber . init ( value: v) , forKey: key)
393393 }
394394 get {
395- let key = NSAttributedStringKey ( UIAccessibilitySpeechAttributeQueueAnnouncement )
395+ let key = NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilitySpeechQueueAnnouncement ) )
396396 if let n: NSNumber = self . get ( attributeForKey: key) {
397397 return n. boolValue
398398 } else { return false }
@@ -405,15 +405,15 @@ public class Style: StyleProtocol {
405405 @available ( iOS 11 . 0 , tvOS 11 . 0 , iOSApplicationExtension 11 . 0 , watchOS 4 , * )
406406 public var headingLevel : HeadingLevel ? {
407407 set {
408- let key = NSAttributedStringKey ( UIAccessibilityTextAttributeHeadingLevel )
408+ let key = NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilityTextHeadingLevel ) )
409409 guard let v = newValue else {
410410 self . innerAttributes. removeValue ( forKey: key)
411411 return
412412 }
413413 self . set ( attribute: v. rawValue, forKey: key)
414414 }
415415 get {
416- let key = NSAttributedStringKey ( UIAccessibilityTextAttributeHeadingLevel )
416+ let key = NSAttributedString . Key ( convertFromNSAttributedStringKey ( NSAttributedString . Key . accessibilityTextHeadingLevel ) )
417417 if let n: Int = self . get ( attributeForKey: key) {
418418 return HeadingLevel ( rawValue: n)
419419 } else { return nil }
@@ -546,7 +546,7 @@ public class Style: StyleProtocol {
546546 /// Font related attributes are not set automatically but are encapsulasted to the font object itself.
547547 ///
548548 /// - Parameter dictionary: dictionary to set
549- public init ( dictionary: [ NSAttributedStringKey : Any ] ? ) {
549+ public init ( dictionary: [ NSAttributedString . Key : Any ] ? ) {
550550 self . fontData? . style = self
551551 if let font = dictionary ? [ . font] as? Font {
552552 self . fontData? . font = font
@@ -578,7 +578,7 @@ public class Style: StyleProtocol {
578578 /// - Parameters:
579579 /// - value: valid value to set, `nil` to remove exiting value for given key.
580580 /// - key: key to set
581- public func set< T> ( attribute value: T ? , forKey key: NSAttributedStringKey ) {
581+ public func set< T> ( attribute value: T ? , forKey key: NSAttributedString . Key ) {
582582 guard let value = value else {
583583 self . innerAttributes. removeValue ( forKey: key)
584584 return
@@ -591,12 +591,12 @@ public class Style: StyleProtocol {
591591 ///
592592 /// - Parameter key: key to read.
593593 /// - Returns: value or `nil` if value is not set.
594- public func get< T> ( attributeForKey key: NSAttributedStringKey ) -> T ? {
594+ public func get< T> ( attributeForKey key: NSAttributedString . Key ) -> T ? {
595595 return ( self . innerAttributes [ key] as? T )
596596 }
597597
598598 /// Return all attributes defined by the style.
599- public var attributes : [ NSAttributedStringKey : Any ] {
599+ public var attributes : [ NSAttributedString . Key : Any ] {
600600 if let cachedAttributes = self . cachedAttributes {
601601 return cachedAttributes
602602 }
@@ -617,3 +617,8 @@ public class Style: StyleProtocol {
617617 return styleCopy
618618 }
619619}
620+
621+ // Helper function inserted by Swift 4.2 migrator.
622+ fileprivate func convertFromNSAttributedStringKey( _ input: NSAttributedString . Key ) -> String {
623+ return input. rawValue
624+ }
0 commit comments