diff --git a/Attributed.xcodeproj/project.pbxproj b/Attributed.xcodeproj/project.pbxproj index 535a79b..6d69995 100644 --- a/Attributed.xcodeproj/project.pbxproj +++ b/Attributed.xcodeproj/project.pbxproj @@ -201,12 +201,12 @@ TargetAttributes = { AAEE626C1DF8F3690079C70C = { CreatedOnToolsVersion = 8.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; AAEE62751DF8F3690079C70C = { CreatedOnToolsVersion = 8.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; }; @@ -413,8 +413,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -433,8 +432,7 @@ PRODUCT_BUNDLE_IDENTIFIER = attributed.Attributed; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -446,8 +444,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = attributed.AttributedTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -459,8 +456,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = attributed.AttributedTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Attributed/Attributes.swift b/Attributed/Attributes.swift index 0ee6fa7..c3c6e9f 100644 --- a/Attributed/Attributes.swift +++ b/Attributed/Attributes.swift @@ -26,7 +26,7 @@ import Foundation public struct Attributes { - public let dictionary: [NSAttributedStringKey: Any] + public let dictionary: [NSAttributedString.Key: Any] public init() { dictionary = [:] @@ -36,62 +36,62 @@ public struct Attributes { self = attributesBlock(Attributes()) } - internal init(dictionary: [NSAttributedStringKey: Any]) { + internal init(dictionary: [NSAttributedString.Key: Any]) { self.dictionary = dictionary } public func font(_ font: UIFont) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.font: font]) + return self + Attributes(dictionary: [NSAttributedString.Key.font: font]) } public func kerning(_ kerning: Double) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.kern: NSNumber(floatLiteral: kerning)]) + return self + Attributes(dictionary: [NSAttributedString.Key.kern: NSNumber(floatLiteral: kerning)]) } public func strikeThroughStyle(_ strikeThroughStyle: NSUnderlineStyle) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.strikethroughStyle: strikeThroughStyle.rawValue, - NSAttributedStringKey.baselineOffset : NSNumber(floatLiteral: 1.5), + return self + Attributes(dictionary: [NSAttributedString.Key.strikethroughStyle: strikeThroughStyle.rawValue, + NSAttributedString.Key.baselineOffset : NSNumber(floatLiteral: 1.5), ]) } public func underlineStyle(_ underlineStyle: NSUnderlineStyle) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.underlineStyle: underlineStyle.rawValue]) + return self + Attributes(dictionary: [NSAttributedString.Key.underlineStyle: underlineStyle.rawValue]) } public func strokeColor(_ strokeColor: UIColor) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.strokeColor: strokeColor]) + return self + Attributes(dictionary: [NSAttributedString.Key.strokeColor: strokeColor]) } public func strokeWidth(_ strokewidth: Double) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.strokeWidth: NSNumber(floatLiteral: strokewidth)]) + return self + Attributes(dictionary: [NSAttributedString.Key.strokeWidth: NSNumber(floatLiteral: strokewidth)]) } public func foreground(color: UIColor) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.foregroundColor: color]) + return self + Attributes(dictionary: [NSAttributedString.Key.foregroundColor: color]) } public func background(color: UIColor) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.backgroundColor: color]) + return self + Attributes(dictionary: [NSAttributedString.Key.backgroundColor: color]) } public func paragraphStyle(_ paragraphStyle: NSParagraphStyle) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func shadow(_ shadow: NSShadow) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.shadow: shadow]) + return self + Attributes(dictionary: [NSAttributedString.Key.shadow: shadow]) } public func obliqueness(_ value: CGFloat) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.obliqueness: value]) + return self + Attributes(dictionary: [NSAttributedString.Key.obliqueness: value]) } public func link(_ link: String) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.link: link]) + return self + Attributes(dictionary: [NSAttributedString.Key.link: link]) } public func baselineOffset(_ offset: NSNumber) -> Attributes { - return self + Attributes(dictionary: [NSAttributedStringKey.baselineOffset: offset]) + return self + Attributes(dictionary: [NSAttributedString.Key.baselineOffset: offset]) } } @@ -100,57 +100,57 @@ public struct Attributes { extension Attributes { public func lineSpacing(_ lineSpacing: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.lineSpacing = lineSpacing - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func paragraphSpacing(_ paragraphSpacing: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.paragraphSpacing = paragraphSpacing - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func alignment(_ alignment: NSTextAlignment) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.alignment = alignment - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func firstLineHeadIndent(_ firstLineHeadIndent: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.firstLineHeadIndent = firstLineHeadIndent - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func headIndent(_ headIndent: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.headIndent = headIndent - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func tailIndent(_ tailIndent: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.tailIndent = tailIndent - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func lineBreakMode(_ lineBreakMode: NSLineBreakMode) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.lineBreakMode = lineBreakMode - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func minimumLineHeight(_ minimumLineHeight: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.minimumLineHeight = minimumLineHeight - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func maximumLineHeight(_ maximumLineHeight: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.maximumLineHeight = maximumLineHeight - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func uniformLineHeight(_ uniformLineHeight: CGFloat) -> Attributes { @@ -158,26 +158,26 @@ extension Attributes { } public func baseWritingDirection(_ baseWritingDirection: NSWritingDirection) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.baseWritingDirection = baseWritingDirection - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func lineHeightMultiple(_ lineHeightMultiple: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.lineHeightMultiple = lineHeightMultiple - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func paragraphSpacingBefore(_ paragraphSpacingBefore: CGFloat) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.paragraphSpacingBefore = paragraphSpacingBefore - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } public func hyphenationFactor(_ hyphenationFactor: Float) -> Attributes { - let paragraphStyle = (dictionary[NSAttributedStringKey.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle + let paragraphStyle = (dictionary[NSAttributedString.Key.paragraphStyle] ?? NSMutableParagraphStyle.default.mutableCopy()) as! NSMutableParagraphStyle paragraphStyle.hyphenationFactor = hyphenationFactor - return self + Attributes(dictionary: [NSAttributedStringKey.paragraphStyle: paragraphStyle]) + return self + Attributes(dictionary: [NSAttributedString.Key.paragraphStyle: paragraphStyle]) } } diff --git a/Attributed/Operators.swift b/Attributed/Operators.swift index cc19a29..afc318b 100644 --- a/Attributed/Operators.swift +++ b/Attributed/Operators.swift @@ -114,8 +114,8 @@ public func + (lhs: Attributes, rhs: Attributes) -> Attributes { } let combinedParagraphStyle: NSParagraphStyle? - let lhsParagraphStyle = lhs.dictionary[NSAttributedStringKey.paragraphStyle] as? NSParagraphStyle - let rhsParagraphStyle = rhs.dictionary[NSAttributedStringKey.paragraphStyle] as? NSParagraphStyle + let lhsParagraphStyle = lhs.dictionary[NSAttributedString.Key.paragraphStyle] as? NSParagraphStyle + let rhsParagraphStyle = rhs.dictionary[NSAttributedString.Key.paragraphStyle] as? NSParagraphStyle if let lhsParagraphStyle = lhsParagraphStyle, let rhsParagraphStyle = rhsParagraphStyle { combinedParagraphStyle = lhsParagraphStyle + rhsParagraphStyle @@ -124,7 +124,7 @@ public func + (lhs: Attributes, rhs: Attributes) -> Attributes { } if let paragraphStyle = combinedParagraphStyle { - combined[NSAttributedStringKey.paragraphStyle] = paragraphStyle + combined[NSAttributedString.Key.paragraphStyle] = paragraphStyle } return Attributes(dictionary: combined) diff --git a/AttributedTests/AttributesTests.swift b/AttributedTests/AttributesTests.swift index 578cb3c..22c1deb 100644 --- a/AttributedTests/AttributesTests.swift +++ b/AttributedTests/AttributesTests.swift @@ -26,13 +26,13 @@ import XCTest class AttributesTests: XCTestCase { func testFont() { - let expected: [String: Any] = [NSAttributedStringKey.font.rawValue: UIFont.systemFont(ofSize: 12.0)] + let expected: [String: Any] = [NSAttributedString.Key.font.rawValue: UIFont.systemFont(ofSize: 12.0)] let attributed = Attributes().font(.systemFont(ofSize: 12.0)) XCTAssert(attributed.dictionary.keys.first!.rawValue == expected.keys.first!, "Font is broken") } func testBaselineOffset() { - let expected: [String: Any] = [NSAttributedStringKey.baselineOffset.rawValue: NSNumber(value: 1)] + let expected: [String: Any] = [NSAttributedString.Key.baselineOffset.rawValue: NSNumber(value: 1)] let attributed = Attributes().baselineOffset(1) XCTAssert(attributed.dictionary.keys.first!.rawValue == expected.keys.first!, "NSBaselineOffsetAttributeName functionality is broken") }