Skip to content

Commit 8e2bffd

Browse files
committed
Fix Swift 4.1 build on Xcode 9.
1 parent 3e4077c commit 8e2bffd

9 files changed

+51
-49
lines changed

SwiftyAttributes/Sources/common/Attribute+Sequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
An extension on dictionaries that allows us to convert a Foundation-based dictionary of attributes to an array of `Attribute`s.
1111
*/
1212
#if swift(>=4.0)
13-
extension Dictionary where Key == NSAttributedString.Key {
13+
extension Dictionary where Key == AttributeName {
1414

1515
/// Returns an array of `Attribute`s converted from the dictionary of attributes. Use this whenever you want to convert [NSAttributeStringKey: Any] to [Attribute].
1616
public var swiftyAttributes: [Attribute] {

SwiftyAttributes/Sources/common/Attribute.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ public typealias Shadow = NSShadow
2828
public typealias TextAttachment = NSTextAttachment
2929
#endif
3030

31-
#if swift(>=4.0)
31+
#if swift(>=4.2)
3232
public typealias AttributeName = NSAttributedString.Key
33+
#elseif swift(>=4.0)
34+
public typealias AttributeName = NSAttributedStringKey
3335
#else
3436
public typealias AttributeName = Attribute.Name
3537
#endif

SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
#if swift(>=4.0)
12-
public typealias StringKey = NSAttributedString.Key
12+
public typealias StringKey = AttributeName
1313
#else
1414
public typealias StringKey = String
1515
#endif

SwiftyAttributesTests/Attribute+Sequence_Tests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Attribute_Sequence_Tests: XCTestCase {
1313

1414
func testDictionaryToSwiftyAttributes() {
1515
#if swift(>=4.0)
16-
let dict: [NSAttributedString.Key: Any] = [
16+
let dict: [AttributeName: Any] = [
1717
.baselineOffset: 3.2,
1818
.expansion: 5,
1919
.foregroundColor: Color.red
@@ -37,7 +37,7 @@ class Attribute_Sequence_Tests: XCTestCase {
3737

3838
func testDictionaryToSwiftyAttributes_withCustomValues() {
3939
#if swift(>=4.0)
40-
let dict: [NSAttributedString.Key: Any] = [
40+
let dict: [AttributeName: Any] = [
4141
.baselineOffset: 3.2,
4242
.foregroundColor: Color.red,
4343
.init("Foo"): 5
@@ -66,7 +66,7 @@ class Attribute_Sequence_Tests: XCTestCase {
6666
.custom("Foo", 42)
6767
]
6868
#if swift(>=4.0)
69-
let expected: [NSAttributedString.Key: Any] = [
69+
let expected: [AttributeName: Any] = [
7070
.kern: 3.5,
7171
.link: URL(string: "www.google.com")!,
7272
.init(rawValue: "Foo"): 42

SwiftyAttributesTests/NSAttributedString_Tests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class NSAttributedString_Tests: XCTestCase {
452452
func testFontAttributes_onlyFontAttributes() {
453453
let subject = "Hello".withFont(.systemFont(ofSize: 19)).fontAttributes(in: 0 ..< 3).foundationAttributes
454454
#if swift(>=4.0)
455-
let attributeName = NSAttributedString.Key.font
455+
let attributeName = AttributeName.font
456456
#else
457457
let attributeName = NSFontAttributeName
458458
#endif
@@ -465,8 +465,8 @@ class NSAttributedString_Tests: XCTestCase {
465465
let url = URL(string: "www.google.com")!
466466
let subject = "Hello".withAttributes([.font(.systemFont(ofSize: 19)), .link(url)]).fontAttributes(in: 0 ..< 3).foundationAttributes
467467
#if swift(>=4.0)
468-
let fontAttributeName = NSAttributedString.Key.font
469-
let linkAttributeName = NSAttributedString.Key.link
468+
let fontAttributeName = AttributeName.font
469+
let linkAttributeName = AttributeName.link
470470
#else
471471
let fontAttributeName = NSFontAttributeName
472472
let linkAttributeName = NSLinkAttributeName
@@ -483,7 +483,7 @@ class NSAttributedString_Tests: XCTestCase {
483483
style.alignment = .center
484484
let subject = "Hello".withParagraphStyle(style).rulerAttributes(in: 1 ..< 3).foundationAttributes
485485
#if swift(>=4.0)
486-
let attributeName = NSAttributedString.Key.paragraphStyle
486+
let attributeName = AttributeName.paragraphStyle
487487
#else
488488
let attributeName = NSParagraphStyleAttributeName
489489
#endif

SwiftyAttributesTests/NSMutableAttributedString_Tests.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NSMutableAttributedString_Tests: XCTestCase {
1818
subject.addAttributes([.link(URL(string: "https://google.com")!)], range: 1 ..< 3)
1919
XCTAssertNotEqual(subject, expected)
2020
#if swift(>=4.0)
21-
let linkAttributeName = NSAttributedString.Key.link
21+
let linkAttributeName = AttributeName.link
2222
#else
2323
let linkAttributeName = NSLinkAttributeName
2424
#endif
@@ -33,7 +33,7 @@ class NSMutableAttributedString_Tests: XCTestCase {
3333
subject.addAttributes([.font(.boldSystemFont(ofSize: 17))], range: NSRange(location: 0, length: 1))
3434
XCTAssertNotEqual(subject, expected)
3535
#if swift(>=4.0)
36-
let fontAttributeName = NSAttributedString.Key.font
36+
let fontAttributeName = AttributeName.font
3737
#else
3838
let fontAttributeName = NSFontAttributeName
3939
#endif
@@ -48,7 +48,7 @@ class NSMutableAttributedString_Tests: XCTestCase {
4848
subject.setAttributes([.backgroundColor(.orange)], range: 0 ..< 3)
4949
XCTAssertNotEqual(subject, expected)
5050
#if swift(>=4.0)
51-
let attributeName = NSAttributedString.Key.backgroundColor
51+
let attributeName = AttributeName.backgroundColor
5252
#else
5353
let attributeName = NSBackgroundColorAttributeName
5454
#endif
@@ -63,7 +63,7 @@ class NSMutableAttributedString_Tests: XCTestCase {
6363
subject.setAttributes([.backgroundColor(.orange)], range: NSRange(location: 2, length: 2))
6464
XCTAssertNotEqual(subject, expected)
6565
#if swift(>=4.0)
66-
let attributeName = NSAttributedString.Key.backgroundColor
66+
let attributeName = AttributeName.backgroundColor
6767
#else
6868
let attributeName = NSBackgroundColorAttributeName
6969
#endif
@@ -88,7 +88,7 @@ class NSMutableAttributedString_Tests: XCTestCase {
8888
subject.replaceCharacters(in: 0 ..< 2, with: "Chi".withBackgroundColor(.magenta))
8989
XCTAssertNotEqual(subject, expected)
9090
#if swift(>=4.0)
91-
let attributeName = NSAttributedString.Key.backgroundColor
91+
let attributeName = AttributeName.backgroundColor
9292
#else
9393
let attributeName = NSBackgroundColorAttributeName
9494
#endif
@@ -113,7 +113,7 @@ class NSMutableAttributedString_Tests: XCTestCase {
113113
subject.removeAttribute(.baselineOffset, range: 1 ..< 4)
114114
XCTAssertNotEqual(subject, expected)
115115
#if swift(>=4.0)
116-
let attributeName = NSAttributedString.Key.baselineOffset
116+
let attributeName = AttributeName.baselineOffset
117117
#else
118118
let attributeName = NSBaselineOffsetAttributeName
119119
#endif

SwiftyAttributesTests/Operators_Tests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Operators_Tests: XCTestCase {
1616
let rhs = "World".withTextColor(.magenta).withBackgroundColor(.orange).withFont(.boldSystemFont(ofSize: 24))
1717
let newString = lhs + rhs
1818
#if swift(>=4.0)
19-
let leftAttributes: [NSAttributedString.Key: NSObject] = [.font: Font.systemFont(ofSize: 19)]
19+
let leftAttributes: [AttributeName: NSObject] = [.font: Font.systemFont(ofSize: 19)]
2020
XCTAssertEqual(newString.attributes(at: 0, effectiveRange: nil) as NSDictionary, leftAttributes as NSDictionary)
21-
let rightAttributes: [NSAttributedString.Key: NSObject] = [
21+
let rightAttributes: [AttributeName: NSObject] = [
2222
.foregroundColor: Color.magenta,
2323
.backgroundColor: Color.orange,
2424
.font: Font.boldSystemFont(ofSize: 24)

0 commit comments

Comments
 (0)