Skip to content

Commit bafd948

Browse files
committed
Merge branch 'release/2.0.5'
2 parents c4fbcaa + dc9567d commit bafd948

File tree

13 files changed

+78
-66
lines changed

13 files changed

+78
-66
lines changed

Configs/SwiftRichString.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.0.2</string>
18+
<string>2.0.5</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

ExampleWatchOS/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@
3737
"size" : "44x44",
3838
"idiom" : "watch",
3939
"scale" : "2x",
40-
"role" : "longLook",
41-
"subtype" : "42mm"
40+
"role" : "appLauncher",
41+
"subtype" : "40mm"
42+
},
43+
{
44+
"size" : "50x50",
45+
"idiom" : "watch",
46+
"scale" : "2x",
47+
"role" : "appLauncher",
48+
"subtype" : "44mm"
4249
},
4350
{
4451
"size" : "86x86",
@@ -53,6 +60,25 @@
5360
"scale" : "2x",
5461
"role" : "quickLook",
5562
"subtype" : "42mm"
63+
},
64+
{
65+
"size" : "108x108",
66+
"idiom" : "watch",
67+
"scale" : "2x",
68+
"role" : "quickLook",
69+
"subtype" : "44mm"
70+
},
71+
{
72+
"idiom" : "watch-marketing",
73+
"size" : "1024x1024",
74+
"scale" : "1x"
75+
},
76+
{
77+
"size" : "44x44",
78+
"idiom" : "watch",
79+
"scale" : "2x",
80+
"role" : "longLook",
81+
"subtype" : "42mm"
5682
}
5783
],
5884
"info" : {

ExampleiOS/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
17+
private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}

Sources/SwiftRichString/Attributes/CommonsAttributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import CoreGraphics
5454
public typealias Image = UIImage
5555
public typealias Font = UIFont
5656
public typealias FontDescriptor = UIFontDescriptor
57-
public typealias SymbolicTraits = UIFontDescriptorSymbolicTraits
57+
public typealias SymbolicTraits = UIFontDescriptor.SymbolicTraits
5858
public typealias LineBreak = NSLineBreakMode
5959

6060
let FontDescriptorFeatureSettingsAttribute = UIFontDescriptor.AttributeName.featureSettings

Sources/SwiftRichString/Attributes/FontData.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class FontData {
100100
///
101101
/// - Parameter size: ignored. It will be overriden by `fontSize` property.
102102
/// - Returns: instance of the font
103-
var attributes: [NSAttributedStringKey:Any] {
103+
var attributes: [NSAttributedString.Key:Any] {
104104
guard !self.explicitFont else {
105105
return [:]
106106
}
@@ -139,8 +139,8 @@ public class FontData {
139139
/// - currentFont: current font.
140140
/// - currentSize: current font size.
141141
/// - Returns: attributes
142-
public func attributes(currentFont: FontConvertible?, size currentSize: CGFloat?) -> [NSAttributedStringKey:Any] {
143-
var finalAttributes: [NSAttributedStringKey:Any] = [:]
142+
public func attributes(currentFont: FontConvertible?, size currentSize: CGFloat?) -> [NSAttributedString.Key:Any] {
143+
var finalAttributes: [NSAttributedString.Key:Any] = [:]
144144

145145
// generate an initial font from passed FontConvertible instance
146146
guard let size = (self.size ?? currentSize) else { return [:] }

Sources/SwiftRichString/Extensions/AttributedString+Ext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public extension AttributedString {
146146
/// - range: range of substring where style will be removed, `nil` to use the entire string.
147147
/// - Returns: same instance of the receiver with - eventually - modified attributes.
148148
@discardableResult
149-
public func removeAttributes(_ keys: [NSAttributedStringKey], range: NSRange) -> Self {
149+
public func removeAttributes(_ keys: [NSAttributedString.Key], range: NSRange) -> Self {
150150
keys.forEach { self.removeAttribute($0, range: range) }
151151
return self
152152
}
@@ -156,7 +156,7 @@ public extension AttributedString {
156156
/// - Parameter style: style to use.
157157
/// - Returns: same instance of the receiver with - eventually - modified attributes.
158158
public func remove(_ style: StyleProtocol) -> Self {
159-
self.removeAttributes(Array(style.attributes.keys), range: NSMakeRange(0, self.string.count))
159+
self.removeAttributes(Array(style.attributes.keys), range: NSMakeRange(0, self.length))
160160
return self
161161
}
162162

Sources/SwiftRichString/Style/Style.swift

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

Sources/SwiftRichString/Style/StyleGroup.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ public class StyleGroup: StyleProtocol {
8383

8484
/// Return all attributes merge of each single `Style` of the group.
8585
/// Attributes are reported in order of the insertion regardeless the associated name.
86-
public var attributes: [NSAttributedStringKey : Any] {
87-
var composedAttributes: [NSAttributedStringKey: Any] = [:]
88-
self.styles.enumerated().forEach { (_,style) in
86+
public var attributes: [NSAttributedString.Key : Any] {
87+
var composedAttributes: [NSAttributedString.Key: Any] = [:]
88+
self.styles.enumerated().forEach { (arg) in
89+
90+
let (_, style) = arg
8991
composedAttributes.merge(style.attributes, uniquingKeysWith: { (_, new) in return new })
9092
}
9193
return composedAttributes
@@ -257,7 +259,7 @@ public extension Array where Array.Element == StyleProtocol {
257259
///
258260
/// - Returns: merged style
259261
public func mergeStyle() -> Style {
260-
var attributes: [NSAttributedStringKey:Any] = [:]
262+
var attributes: [NSAttributedString.Key:Any] = [:]
261263
self.forEach { attributes.merge($0.attributes, uniquingKeysWith: { (_, new) in return new }) }
262264
return Style(dictionary: attributes)
263265
}

Sources/SwiftRichString/Style/StyleProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public typealias AttributedString = NSMutableAttributedString
3535
public protocol StyleProtocol: class {
3636

3737
/// Return the attributes of the style in form of dictionary `NSAttributedStringKey`/`Any`.
38-
var attributes: [NSAttributedStringKey : Any] { get }
38+
var attributes: [NSAttributedString.Key : Any] { get }
3939

4040
/// Font unique attributes dictionary.
4141
var fontData: FontData? { get }
@@ -56,7 +56,7 @@ public extension StyleProtocol {
5656
func set(to source: String, range: NSRange?) -> AttributedString {
5757
let attributedText = NSMutableAttributedString(string: source)
5858
self.fontData?.addAttributes(to: attributedText, range: nil)
59-
attributedText.addAttributes(self.attributes, range: (range ?? NSMakeRange(0, source.count)))
59+
attributedText.addAttributes(self.attributes, range: (range ?? NSMakeRange(0, attributedText.length)))
6060
return attributedText
6161
}
6262

Sources/SwiftRichString/Style/StyleRegEx.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class StyleRegEx: StyleProtocol {
5151
private var style: StyleProtocol
5252

5353
/// Style attributes
54-
public var attributes: [NSAttributedStringKey : Any] {
54+
public var attributes: [NSAttributedString.Key : Any] {
5555
return self.style.attributes
5656
}
5757

@@ -90,14 +90,14 @@ public class StyleRegEx: StyleProtocol {
9090

9191
public func add(to source: AttributedString, range: NSRange?) -> AttributedString {
9292
if let base = self.baseStyle {
93-
source.addAttributes(base.attributes, range: (range ?? NSMakeRange(0, source.string.count)))
93+
source.addAttributes(base.attributes, range: (range ?? NSMakeRange(0, source.length)))
9494
}
9595
return self.applyStyle(to: source, add: true, range: range)
9696
}
9797

9898
public func set(to source: AttributedString, range: NSRange?) -> AttributedString {
9999
if let base = self.baseStyle {
100-
source.setAttributes(base.attributes, range: (range ?? NSMakeRange(0, source.string.count)))
100+
source.setAttributes(base.attributes, range: (range ?? NSMakeRange(0, source.length)))
101101
}
102102
return self.applyStyle(to: source, add: false, range: range)
103103
}
@@ -112,7 +112,7 @@ public class StyleRegEx: StyleProtocol {
112112
/// - range: range, `nil` to apply the style to entire string.
113113
/// - Returns: modified attributed string
114114
private func applyStyle(to str: AttributedString, add: Bool, range: NSRange?) -> AttributedString {
115-
let rangeValue = (range ?? NSMakeRange(0, str.string.count))
115+
let rangeValue = (range ?? NSMakeRange(0, str.length))
116116

117117
let matchOpts = NSRegularExpression.MatchingOptions(rawValue: 0)
118118
self.regex.enumerateMatches(in: str.string, options: matchOpts, range: rangeValue) {

0 commit comments

Comments
 (0)