diff --git a/SwiftyAttributes.podspec b/SwiftyAttributes.podspec index 63a40ac..28ade25 100644 --- a/SwiftyAttributes.podspec +++ b/SwiftyAttributes.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = "SwiftyAttributes" - s.version = "4.2.0" + s.version = "4.3.0" s.summary = "A Swifty API for attributed strings." s.description = <<-DESC diff --git a/SwiftyAttributes/Sources/common/Attribute+Sequence.swift b/SwiftyAttributes/Sources/common/Attribute+Sequence.swift index 81b8f29..1451ec7 100644 --- a/SwiftyAttributes/Sources/common/Attribute+Sequence.swift +++ b/SwiftyAttributes/Sources/common/Attribute+Sequence.swift @@ -10,7 +10,7 @@ An extension on dictionaries that allows us to convert a Foundation-based dictionary of attributes to an array of `Attribute`s. */ #if swift(>=4.0) - extension Dictionary where Key == NSAttributedStringKey { + extension Dictionary where Key == AttributeName { /// Returns an array of `Attribute`s converted from the dictionary of attributes. Use this whenever you want to convert [NSAttributeStringKey: Any] to [Attribute]. public var swiftyAttributes: [Attribute] { diff --git a/SwiftyAttributes/Sources/common/Attribute.swift b/SwiftyAttributes/Sources/common/Attribute.swift index ec1ce1c..0d96841 100644 --- a/SwiftyAttributes/Sources/common/Attribute.swift +++ b/SwiftyAttributes/Sources/common/Attribute.swift @@ -28,7 +28,9 @@ public typealias Shadow = NSShadow public typealias TextAttachment = NSTextAttachment #endif -#if swift(>=4.0) +#if swift(>=4.2) + public typealias AttributeName = NSAttributedString.Key +#elseif swift(>=4.0) public typealias AttributeName = NSAttributedStringKey #else public typealias AttributeName = Attribute.Name @@ -188,11 +190,23 @@ public enum Attribute { case .strokeColor: ret = .strokeColor(validate(foundationValue)) case .strokeWidth: ret = .strokeWidth(validateDouble(foundationValue)) case .strikethroughColor: ret = .strikethroughColor(validate(foundationValue)) - case .strikethroughStyle: ret = .strikethroughStyle(StrikethroughStyle(rawValue: validate(foundationValue))!) + case .strikethroughStyle: + #if swift(>=4.2) + let style = StrikethroughStyle(rawValue: validate(foundationValue)) + #else + let style = StrikethroughStyle(rawValue: validate(foundationValue))! + #endif + ret = .strikethroughStyle(style) case .foregroundColor: ret = .textColor(validate(foundationValue)) case .textEffect: ret = .textEffect(TextEffect(rawValue: validate(foundationValue))!) case .underlineColor: ret = .underlineColor(validate(foundationValue)) - case .underlineStyle: ret = .underlineStyle(UnderlineStyle(rawValue: validate(foundationValue))!) + case .underlineStyle: + #if swift(>=4.2) + let style = UnderlineStyle(rawValue: validate(foundationValue)) + #else + let style = UnderlineStyle(rawValue: validate(foundationValue))! + #endif + ret = .underlineStyle(style) case .verticalGlyphForm: ret = .verticalGlyphForm(VerticalGlyphForm(rawValue: validate(foundationValue))!) case .writingDirection: let values: [Int] = validate(foundationValue) diff --git a/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift b/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift index 5eca031..76a0b01 100644 --- a/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift +++ b/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift @@ -9,7 +9,7 @@ import Foundation #if swift(>=4.0) - public typealias StringKey = NSAttributedStringKey + public typealias StringKey = AttributeName #else public typealias StringKey = String #endif diff --git a/SwiftyAttributesTests/Attribute+Sequence_Tests.swift b/SwiftyAttributesTests/Attribute+Sequence_Tests.swift index 5a9015c..27f2061 100644 --- a/SwiftyAttributesTests/Attribute+Sequence_Tests.swift +++ b/SwiftyAttributesTests/Attribute+Sequence_Tests.swift @@ -13,47 +13,47 @@ class Attribute_Sequence_Tests: XCTestCase { func testDictionaryToSwiftyAttributes() { #if swift(>=4.0) - let dict: [NSAttributedStringKey: Any] = [ + let dict: [AttributeName: Any] = [ .baselineOffset: 3.2, .expansion: 5, - .underlineStyle: NSUnderlineStyle.styleDouble.rawValue + .foregroundColor: Color.red ] let sort: (Attribute, Attribute) -> Bool = { $0.keyName.rawValue < $1.keyName.rawValue } #else let dict: [String: Any] = [ NSBaselineOffsetAttributeName: 3.2, NSExpansionAttributeName: 5, - NSUnderlineStyleAttributeName: NSUnderlineStyle.styleDouble.rawValue + NSForegroundColorAttributeName: Color.red ] let sort: (Attribute, Attribute) -> Bool = { $0.0.keyName < $0.1.keyName } #endif let expected: [Attribute] = [ .baselineOffset(3.2), .expansion(5), - .underlineStyle(.styleDouble) + .textColor(.red) ].sorted(by: sort) XCTAssertEqual(dict.swiftyAttributes.sorted(by: sort), expected) } func testDictionaryToSwiftyAttributes_withCustomValues() { #if swift(>=4.0) - let dict: [NSAttributedStringKey: Any] = [ + let dict: [AttributeName: Any] = [ .baselineOffset: 3.2, - .underlineStyle: NSUnderlineStyle.styleDouble.rawValue, + .foregroundColor: Color.red, .init("Foo"): 5 ] let sort: (Attribute, Attribute) -> Bool = { $0.keyName.rawValue < $1.keyName.rawValue } #else let dict: [String: Any] = [ NSBaselineOffsetAttributeName: 3.2, - NSUnderlineStyleAttributeName: NSUnderlineStyle.styleDouble.rawValue, + NSForegroundColorAttributeName: Color.red, "Foo": 5 ] let sort: (Attribute, Attribute) -> Bool = { $0.0.keyName < $0.1.keyName } #endif let expected: [Attribute] = [ .baselineOffset(3.2), - .underlineStyle(.styleDouble), + .textColor(.red), .custom("Foo", 5) ].sorted(by: sort) XCTAssertEqual(dict.swiftyAttributes.sorted(by: sort), expected) @@ -66,7 +66,7 @@ class Attribute_Sequence_Tests: XCTestCase { .custom("Foo", 42) ] #if swift(>=4.0) - let expected: [NSAttributedStringKey: Any] = [ + let expected: [AttributeName: Any] = [ .kern: 3.5, .link: URL(string: "www.google.com")!, .init(rawValue: "Foo"): 42 diff --git a/SwiftyAttributesTests/NSAttributedString_Tests.swift b/SwiftyAttributesTests/NSAttributedString_Tests.swift index b73cb64..60947b3 100644 --- a/SwiftyAttributesTests/NSAttributedString_Tests.swift +++ b/SwiftyAttributesTests/NSAttributedString_Tests.swift @@ -212,7 +212,14 @@ class NSAttributedString_Tests: XCTestCase { } func testAttributeAtLocation_strikethroughStyle() { - let str = "Hello".withStrikethroughStyle(.styleDouble) + let style: NSUnderlineStyle + #if swift(>=4.2) + style = .double + #else + style = .styleDouble + #endif + + let str = "Hello".withStrikethroughStyle(style) let subject = str.swiftyAttribute(.strikethroughStyle, at: 0, effectiveRange: nil)!.value as! StrikethroughStyle #if swift(>=4.0) let expected = str.attribute(.strikethroughStyle, at: 0, effectiveRange: nil) as! Int @@ -220,7 +227,11 @@ class NSAttributedString_Tests: XCTestCase { let expected = str.attribute(NSStrikethroughStyleAttributeName, at: 0, effectiveRange: nil) as! Int #endif XCTAssertEqual(subject.rawValue, expected) - XCTAssertEqual(subject, .styleDouble) + #if swift(>=4.2) + XCTAssertEqual(subject, .double) + #else + XCTAssertEqual(subject, .styleDouble) + #endif } func testAttributeAtLocation_textColor() { @@ -441,7 +452,7 @@ class NSAttributedString_Tests: XCTestCase { func testFontAttributes_onlyFontAttributes() { let subject = "Hello".withFont(.systemFont(ofSize: 19)).fontAttributes(in: 0 ..< 3).foundationAttributes #if swift(>=4.0) - let attributeName = NSAttributedStringKey.font + let attributeName = AttributeName.font #else let attributeName = NSFontAttributeName #endif @@ -454,8 +465,8 @@ class NSAttributedString_Tests: XCTestCase { let url = URL(string: "www.google.com")! let subject = "Hello".withAttributes([.font(.systemFont(ofSize: 19)), .link(url)]).fontAttributes(in: 0 ..< 3).foundationAttributes #if swift(>=4.0) - let fontAttributeName = NSAttributedStringKey.font - let linkAttributeName = NSAttributedStringKey.link + let fontAttributeName = AttributeName.font + let linkAttributeName = AttributeName.link #else let fontAttributeName = NSFontAttributeName let linkAttributeName = NSLinkAttributeName @@ -472,7 +483,7 @@ class NSAttributedString_Tests: XCTestCase { style.alignment = .center let subject = "Hello".withParagraphStyle(style).rulerAttributes(in: 1 ..< 3).foundationAttributes #if swift(>=4.0) - let attributeName = NSAttributedStringKey.paragraphStyle + let attributeName = AttributeName.paragraphStyle #else let attributeName = NSParagraphStyleAttributeName #endif diff --git a/SwiftyAttributesTests/NSMutableAttributedString_Tests.swift b/SwiftyAttributesTests/NSMutableAttributedString_Tests.swift index 557437f..5577b2e 100644 --- a/SwiftyAttributesTests/NSMutableAttributedString_Tests.swift +++ b/SwiftyAttributesTests/NSMutableAttributedString_Tests.swift @@ -18,7 +18,7 @@ class NSMutableAttributedString_Tests: XCTestCase { subject.addAttributes([.link(URL(string: "https://google.com")!)], range: 1 ..< 3) XCTAssertNotEqual(subject, expected) #if swift(>=4.0) - let linkAttributeName = NSAttributedStringKey.link + let linkAttributeName = AttributeName.link #else let linkAttributeName = NSLinkAttributeName #endif @@ -33,7 +33,7 @@ class NSMutableAttributedString_Tests: XCTestCase { subject.addAttributes([.font(.boldSystemFont(ofSize: 17))], range: NSRange(location: 0, length: 1)) XCTAssertNotEqual(subject, expected) #if swift(>=4.0) - let fontAttributeName = NSAttributedStringKey.font + let fontAttributeName = AttributeName.font #else let fontAttributeName = NSFontAttributeName #endif @@ -48,7 +48,7 @@ class NSMutableAttributedString_Tests: XCTestCase { subject.setAttributes([.backgroundColor(.orange)], range: 0 ..< 3) XCTAssertNotEqual(subject, expected) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.backgroundColor + let attributeName = AttributeName.backgroundColor #else let attributeName = NSBackgroundColorAttributeName #endif @@ -63,7 +63,7 @@ class NSMutableAttributedString_Tests: XCTestCase { subject.setAttributes([.backgroundColor(.orange)], range: NSRange(location: 2, length: 2)) XCTAssertNotEqual(subject, expected) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.backgroundColor + let attributeName = AttributeName.backgroundColor #else let attributeName = NSBackgroundColorAttributeName #endif @@ -88,7 +88,7 @@ class NSMutableAttributedString_Tests: XCTestCase { subject.replaceCharacters(in: 0 ..< 2, with: "Chi".withBackgroundColor(.magenta)) XCTAssertNotEqual(subject, expected) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.backgroundColor + let attributeName = AttributeName.backgroundColor #else let attributeName = NSBackgroundColorAttributeName #endif @@ -113,7 +113,7 @@ class NSMutableAttributedString_Tests: XCTestCase { subject.removeAttribute(.baselineOffset, range: 1 ..< 4) XCTAssertNotEqual(subject, expected) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.baselineOffset + let attributeName = AttributeName.baselineOffset #else let attributeName = NSBaselineOffsetAttributeName #endif diff --git a/SwiftyAttributesTests/Operators_Tests.swift b/SwiftyAttributesTests/Operators_Tests.swift index 24b7aa1..41905d8 100644 --- a/SwiftyAttributesTests/Operators_Tests.swift +++ b/SwiftyAttributesTests/Operators_Tests.swift @@ -16,9 +16,9 @@ class Operators_Tests: XCTestCase { let rhs = "World".withTextColor(.magenta).withBackgroundColor(.orange).withFont(.boldSystemFont(ofSize: 24)) let newString = lhs + rhs #if swift(>=4.0) - let leftAttributes: [NSAttributedStringKey: NSObject] = [.font: Font.systemFont(ofSize: 19)] + let leftAttributes: [AttributeName: NSObject] = [.font: Font.systemFont(ofSize: 19)] XCTAssertEqual(newString.attributes(at: 0, effectiveRange: nil) as NSDictionary, leftAttributes as NSDictionary) - let rightAttributes: [NSAttributedStringKey: NSObject] = [ + let rightAttributes: [AttributeName: NSObject] = [ .foregroundColor: Color.magenta, .backgroundColor: Color.orange, .font: Font.boldSystemFont(ofSize: 24) diff --git a/SwiftyAttributesTests/SwiftyAttributes_Tests.swift b/SwiftyAttributesTests/SwiftyAttributes_Tests.swift index 5bf1bbf..adb7e1d 100644 --- a/SwiftyAttributesTests/SwiftyAttributes_Tests.swift +++ b/SwiftyAttributesTests/SwiftyAttributes_Tests.swift @@ -14,7 +14,7 @@ class SwiftyAttributesTests: XCTestCase { func testString_withAttribute() { let subject = "Hello".withAttribute(.strokeWidth(4)) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.strokeWidth + let attributeName = AttributeName.strokeWidth #else let attributeName = NSStrokeWidthAttributeName #endif @@ -27,7 +27,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withFont(font) let subject2 = "Hello".attributedString.withFont(font) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.font + let attributeName = AttributeName.font #else let attributeName = NSFontAttributeName #endif @@ -43,7 +43,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withParagraphStyle(style) let subject2 = "Hello".attributedString.withParagraphStyle(style) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.paragraphStyle + let attributeName = AttributeName.paragraphStyle #else let attributeName = NSParagraphStyleAttributeName #endif @@ -56,7 +56,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withTextColor(.magenta) let subject2 = "Hello".attributedString.withTextColor(.magenta) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.foregroundColor + let attributeName = AttributeName.foregroundColor #else let attributeName = NSForegroundColorAttributeName #endif @@ -69,7 +69,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withBackgroundColor(.cyan) let subject2 = "Hello".attributedString.withBackgroundColor(.cyan) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.backgroundColor + let attributeName = AttributeName.backgroundColor #else let attributeName = NSBackgroundColorAttributeName #endif @@ -82,7 +82,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withLigatures(.none) let subject2 = "Hello".attributedString.withLigatures(.none) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.ligature + let attributeName = AttributeName.ligature #else let attributeName = NSLigatureAttributeName #endif @@ -95,7 +95,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withKern(12) let subject2 = "Hello".attributedString.withKern(12) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.kern + let attributeName = AttributeName.kern #else let attributeName = NSKernAttributeName #endif @@ -108,7 +108,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withStrikethroughStyle(.patternDashDot) let subject2 = "Hello".attributedString.withStrikethroughStyle(.patternDashDot) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.strikethroughStyle + let attributeName = AttributeName.strikethroughStyle #else let attributeName = NSStrikethroughStyleAttributeName #endif @@ -118,14 +118,21 @@ class SwiftyAttributesTests: XCTestCase { } func testAttribute_underlineStyle() { - let subject = "Hello".withUnderlineStyle(.styleDouble) - let subject2 = "Hello".attributedString.withUnderlineStyle(.styleDouble) + let underlineStyle: NSUnderlineStyle + #if swift(>=4.2) + underlineStyle = .double + #else + underlineStyle = .styleDouble + #endif + + let subject = "Hello".withUnderlineStyle(underlineStyle) + let subject2 = "Hello".attributedString.withUnderlineStyle(underlineStyle) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.underlineStyle + let attributeName = AttributeName.underlineStyle #else let attributeName = NSUnderlineStyleAttributeName #endif - let expected = NSAttributedString(string: "Hello", attributes: [attributeName: NSNumber(value: UnderlineStyle.styleDouble.rawValue)]) + let expected = NSAttributedString(string: "Hello", attributes: [attributeName: NSNumber(value: underlineStyle.rawValue)]) XCTAssertEqual(subject, expected) XCTAssertEqual(subject2, expected) } @@ -134,7 +141,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withStrokeColor(.orange) let subject2 = "Hello".attributedString.withStrokeColor(.orange) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.strokeColor + let attributeName = AttributeName.strokeColor #else let attributeName = NSStrokeColorAttributeName #endif @@ -147,7 +154,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withStrokeWidth(3.2) let subject2 = "Hello".attributedString.withStrokeWidth(3.2) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.strokeWidth + let attributeName = AttributeName.strokeWidth #else let attributeName = NSStrokeWidthAttributeName #endif @@ -163,7 +170,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withShadow(shadow) let subject2 = "Hello".attributedString.withShadow(shadow) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.shadow + let attributeName = AttributeName.shadow #else let attributeName = NSShadowAttributeName #endif @@ -189,7 +196,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withAttachment(attachment) let subject2 = "Hello".attributedString.withAttachment(attachment) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.attachment + let attributeName = AttributeName.attachment #else let attributeName = NSAttachmentAttributeName #endif @@ -203,7 +210,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withLink(url) let subject2 = "Hello".attributedString.withLink(url) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.link + let attributeName = AttributeName.link #else let attributeName = NSLinkAttributeName #endif @@ -216,7 +223,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withBaselineOffset(5) let subject2 = "Hello".attributedString.withBaselineOffset(5) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.baselineOffset + let attributeName = AttributeName.baselineOffset #else let attributeName = NSBaselineOffsetAttributeName #endif @@ -229,7 +236,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withUnderlineColor(.magenta) let subject2 = "Hello".attributedString.withUnderlineColor(.magenta) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.underlineColor + let attributeName = AttributeName.underlineColor #else let attributeName = NSUnderlineColorAttributeName #endif @@ -242,7 +249,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withStrikethroughColor(.brown) let subject2 = "Hello".attributedString.withStrikethroughColor(.brown) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.strikethroughColor + let attributeName = AttributeName.strikethroughColor #else let attributeName = NSStrikethroughColorAttributeName #endif @@ -255,7 +262,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withObliqueness(4.5) let subject2 = "Hello".attributedString.withObliqueness(4.5) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.obliqueness + let attributeName = AttributeName.obliqueness #else let attributeName = NSObliquenessAttributeName #endif @@ -268,7 +275,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withExpansion(7) let subject2 = "Hello".attributedString.withExpansion(7) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.expansion + let attributeName = AttributeName.expansion #else let attributeName = NSExpansionAttributeName #endif @@ -281,7 +288,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withVerticalGlyphForm(.horizontal) let subject2 = "Hello".attributedString.withVerticalGlyphForm(.horizontal) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.verticalGlyphForm + let attributeName = AttributeName.verticalGlyphForm #else let attributeName = NSVerticalGlyphFormAttributeName #endif @@ -295,7 +302,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withWritingDirections([.rightToLeftOverride]) let subject2 = "Hello".attributedString.withWritingDirections([.rightToLeftOverride]) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.writingDirection + let attributeName = AttributeName.writingDirection #else let attributeName = NSWritingDirectionAttributeName #endif @@ -308,7 +315,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withCustomAttribute(named: "Foo", value: 42) let subject2 = "Hello".attributedString.withCustomAttribute(named: "Foo", value: 42) #if swift(>=4.0) - let attributeName = NSAttributedStringKey(rawValue: "Foo") + let attributeName = AttributeName(rawValue: "Foo") #else let attributeName = "Foo" #endif @@ -324,7 +331,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withCursor(cursor) let subject2 = "Hello".attributedString.withCursor(cursor) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.cursor + let attributeName = AttributeName.cursor #else let attributeName = NSCursorAttributeName #endif @@ -337,7 +344,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withMarkedClauseSegment(3) let subject2 = "Hello".attributedString.withMarkedClauseSegment(3) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.markedClauseSegment + let attributeName = AttributeName.markedClauseSegment #else let attributeName = NSMarkedClauseSegmentAttributeName #endif @@ -350,7 +357,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withSpellingState(.grammar) let subject2 = "Hello".attributedString.withSpellingState(.grammar) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.spellingState + let attributeName = AttributeName.spellingState #else let attributeName = NSSpellingStateAttributeName #endif @@ -363,7 +370,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withSuperscript(4) let subject2 = "Hello".attributedString.withSuperscript(4) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.superscript + let attributeName = AttributeName.superscript #else let attributeName = NSSuperscriptAttributeName #endif @@ -377,7 +384,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withTextAlternatives(alternatives) let subject2 = "Hello".attributedString.withTextAlternatives(alternatives) #if swift(>=4.0) - let attributeName = NSAttributedStringKey.textAlternatives + let attributeName = AttributeName.textAlternatives #else let attributeName = NSTextAlternativesAttributeName #endif @@ -390,7 +397,7 @@ class SwiftyAttributesTests: XCTestCase { let subject = "Hello".withToolTip("Sah dude") let subject2 = "Hello".attributedString.withToolTip("Sah dude") #if swift(>=4.0) - let attributeName = NSAttributedStringKey.toolTip + let attributeName = AttributeName.toolTip #else let attributeName = NSToolTipAttributeName #endif @@ -404,7 +411,7 @@ class SwiftyAttributesTests: XCTestCase { func testMultipleAttributes_withSyntax() { let subject = "Hello".withTextColor(.darkGray).withBackgroundColor(.magenta).withStrikethroughStyle(.patternDashDotDot) #if swift(>=4.0) - let attrs: [NSAttributedStringKey: Any] = [ + let attrs: [AttributeName: Any] = [ .foregroundColor: Color.darkGray, .backgroundColor: Color.magenta, .strikethroughStyle: UnderlineStyle.patternDashDotDot.rawValue @@ -422,20 +429,20 @@ class SwiftyAttributesTests: XCTestCase { } func testMultipleAttributes_arraySyntax() { - let attributes: [Attribute] = [.font(.boldSystemFont(ofSize: 19)), .link(URL(string: "https://google.com")!), .underlineStyle(.patternSolid)] + let attributes: [Attribute] = [.font(.boldSystemFont(ofSize: 19)), .link(URL(string: "https://google.com")!), .textColor(.blue)] let subject = "Hello".withAttributes(attributes) let subject2 = "Hello".attributedString.withAttributes(attributes) #if swift(>=4.0) - let attrs: [NSAttributedStringKey: Any] = [ + let attrs: [AttributeName: Any] = [ .font: Font.boldSystemFont(ofSize: 19), .link: URL(string: "https://google.com")!, - .underlineStyle: UnderlineStyle.patternSolid.rawValue + .foregroundColor: Color.blue ] #else let attrs: [String: Any] = [ NSFontAttributeName: Font.boldSystemFont(ofSize: 19), NSLinkAttributeName: URL(string: "https://google.com")!, - NSUnderlineStyleAttributeName: UnderlineStyle.patternSolid.rawValue + NSForegroundColorAttributeName: Color.blue ] #endif let expected = NSAttributedString(string: "Hello", attributes: attrs) diff --git a/SwiftyAttributesTests/WritingDirection_Tests.swift b/SwiftyAttributesTests/WritingDirection_Tests.swift index 8796da5..7c12ec9 100644 --- a/SwiftyAttributesTests/WritingDirection_Tests.swift +++ b/SwiftyAttributesTests/WritingDirection_Tests.swift @@ -21,7 +21,7 @@ class WritingDirection_Tests: XCTestCase { NSWritingDirection.rightToLeft.rawValue | NSWritingDirectionFormatType.embedding.rawValue ] #if swift(>=4.0) - let writingAttributeName = NSAttributedStringKey.writingDirection + let writingAttributeName = AttributeName.writingDirection #else let writingAttributeName = NSWritingDirectionAttributeName #endif