From dffc7638d0564520b1142196ed039278b2b92eef Mon Sep 17 00:00:00 2001 From: "J.J. Castro" Date: Sun, 10 Sep 2017 20:10:51 -0500 Subject: [PATCH 1/4] Swift 4.0 compatibility --- .DS_Store | Bin 6148 -> 6148 bytes .swift-version | 2 +- Example/Pods/Pods.xcodeproj/project.pbxproj | 11 +++++++++-- MarkdownKit.podspec | 2 +- MarkdownKit/.DS_Store | Bin 6148 -> 6148 bytes .../Escaping/MarkdownCodeEscaping.swift | 2 +- .../Classes/Elements/MarkdownHeader.swift | 4 ++-- .../Classes/Elements/MarkdownLink.swift | 2 +- MarkdownKit/Classes/MarkdownParser.swift | 2 +- .../Protocols/MarkdownCommonElement.swift | 6 +++--- .../Protocols/MarkdownLevelElement.swift | 12 ++++++------ .../Classes/Protocols/MarkdownStyle.swift | 12 ++++++------ 12 files changed, 31 insertions(+), 24 deletions(-) diff --git a/.DS_Store b/.DS_Store index 6e53a6550c0c30bdf19e4405f6bc9ccb854aebd3..e66559ec4c4568ff078c586401dcf55ec4b1c97f 100644 GIT binary patch delta 110 zcmZoMXfc@JFUrQiz`)4BAi%&-z>vd`no^vclaxPsA>(p;kPJJ6D?<< whJl;G7bsE0kj;?7kk3%gkjLQ7kjYR2F(5yOadI7_*k&chIOv;Y7A delta 51 zcmZoMXfc@JFUrEez`)4BAi%&-%233R%#g}ZoRdEJA>(pJmdOQ-Vw)2fm$OZ5u-nYe H@s}R}Eusy8 diff --git a/.swift-version b/.swift-version index 9f55b2c..5186d07 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.0 diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index b7288f2..a491e71 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -402,6 +402,11 @@ attributes = { LastSwiftUpdateCheck = 0730; LastUpgradeCheck = 0700; + TargetAttributes = { + 3C19A590FD8D7E706D3715FB47281667 = { + LastSwiftMigration = 0900; + }; + }; }; buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 3.2"; @@ -504,7 +509,8 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -571,7 +577,8 @@ PRODUCT_NAME = MarkdownKit; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/MarkdownKit.podspec b/MarkdownKit.podspec index 5fc1935..1d54fbd 100644 --- a/MarkdownKit.podspec +++ b/MarkdownKit.podspec @@ -16,7 +16,7 @@ all the Markdown elements. s.source = { :git => 'https://github.com/ivanbruel/MarkdownKit.git', :tag => s.version.to_s } s.social_media_url = 'https://twitter.com/ivanbruel' - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '9.0' s.source_files = 'MarkdownKit/Classes/**/*' s.frameworks = 'UIKit' diff --git a/MarkdownKit/.DS_Store b/MarkdownKit/.DS_Store index 119e45f281547bc98f4bb473c5f41135060be7ec..46d5588d94ee5648e9a7badbdbe2d4572b4d3141 100644 GIT binary patch delta 39 vcmZoMXfc@J&&a$nU^gQp^JX3(matchString.utf16) diff --git a/MarkdownKit/Classes/Elements/MarkdownHeader.swift b/MarkdownKit/Classes/Elements/MarkdownHeader.swift index 2824fd5..ddf0de9 100644 --- a/MarkdownKit/Classes/Elements/MarkdownHeader.swift +++ b/MarkdownKit/Classes/Elements/MarkdownHeader.swift @@ -34,11 +34,11 @@ open class MarkdownHeader: MarkdownLevelElement { attributedString.deleteCharacters(in: range) } - open func attributesForLevel(_ level: Int) -> [String: AnyObject] { + open func attributesForLevel(_ level: Int) -> [NSAttributedStringKey: AnyObject] { var attributes = self.attributes if let font = font { let headerFontSize: CGFloat = font.pointSize + (CGFloat(level) * CGFloat(fontIncrease)) - attributes[NSFontAttributeName] = font.withSize(headerFontSize) + attributes[NSAttributedStringKey.font] = font.withSize(headerFontSize) } return attributes } diff --git a/MarkdownKit/Classes/Elements/MarkdownLink.swift b/MarkdownKit/Classes/Elements/MarkdownLink.swift index ea12e41..3799412 100644 --- a/MarkdownKit/Classes/Elements/MarkdownLink.swift +++ b/MarkdownKit/Classes/Elements/MarkdownLink.swift @@ -36,7 +36,7 @@ open class MarkdownLink: MarkdownLinkElement { return } guard let url = URL(string: link) ?? URL(string: encodedLink) else { return } - attributedString.addAttribute(NSLinkAttributeName, value: url, range: range) + attributedString.addAttribute(NSAttributedStringKey.link, value: url, range: range) } open func match(_ match: NSTextCheckingResult, attributedString: NSMutableAttributedString) { diff --git a/MarkdownKit/Classes/MarkdownParser.swift b/MarkdownKit/Classes/MarkdownParser.swift index 32a0f5b..fb77949 100644 --- a/MarkdownKit/Classes/MarkdownParser.swift +++ b/MarkdownKit/Classes/MarkdownParser.swift @@ -80,7 +80,7 @@ open class MarkdownParser { open func parse(_ markdown: NSAttributedString) -> NSAttributedString { let attributedString = NSMutableAttributedString(attributedString: markdown) - attributedString.addAttribute(NSFontAttributeName, value: font, + attributedString.addAttribute(NSAttributedStringKey.font, value: font, range: NSRange(location: 0, length: attributedString.length)) var elements: [MarkdownElement] = escapingElements elements.append(contentsOf: defaultElements) diff --git a/MarkdownKit/Classes/Protocols/MarkdownCommonElement.swift b/MarkdownKit/Classes/Protocols/MarkdownCommonElement.swift index 844d80c..b6be99c 100644 --- a/MarkdownKit/Classes/Protocols/MarkdownCommonElement.swift +++ b/MarkdownKit/Classes/Protocols/MarkdownCommonElement.swift @@ -27,10 +27,10 @@ public extension MarkdownCommonElement { func match(_ match: NSTextCheckingResult, attributedString: NSMutableAttributedString) { // deleting trailing markdown - attributedString.deleteCharacters(in: match.rangeAt(4)) + attributedString.deleteCharacters(in: match.range(at: 4)) // formatting string (may alter the length) - addAttributes(attributedString, range: match.rangeAt(3)) + addAttributes(attributedString, range: match.range(at: 3)) // deleting leading markdown - attributedString.deleteCharacters(in: match.rangeAt(2)) + attributedString.deleteCharacters(in: match.range(at: 2)) } } diff --git a/MarkdownKit/Classes/Protocols/MarkdownLevelElement.swift b/MarkdownKit/Classes/Protocols/MarkdownLevelElement.swift index 11bc178..4c83eb7 100644 --- a/MarkdownKit/Classes/Protocols/MarkdownLevelElement.swift +++ b/MarkdownKit/Classes/Protocols/MarkdownLevelElement.swift @@ -17,7 +17,7 @@ public protocol MarkdownLevelElement: MarkdownElement, MarkdownStyle { func formatText(_ attributedString: NSMutableAttributedString, range: NSRange, level: Int) func addAttributes(_ attributedString: NSMutableAttributedString, range: NSRange, level: Int) - func attributesForLevel(_ level: Int) -> [String: AnyObject] + func attributesForLevel(_ level: Int) -> [NSAttributedStringKey: AnyObject] } public extension MarkdownLevelElement { @@ -31,15 +31,15 @@ public extension MarkdownLevelElement { attributedString.addAttributes(attributesForLevel(level - 1), range: range) } - func attributesForLevel(_ level: Int) -> [String: AnyObject] { + func attributesForLevel(_ level: Int) -> [NSAttributedStringKey: AnyObject] { return self.attributes } func match(_ match: NSTextCheckingResult, attributedString: NSMutableAttributedString) { - let level = match.rangeAt(1).length - addAttributes(attributedString, range: match.rangeAt(2), level: level) - let range = NSRange(location: match.rangeAt(1).location, - length: match.rangeAt(2).location - match.rangeAt(1).location) + let level = match.range(at: 1).length + addAttributes(attributedString, range: match.range(at: 2), level: level) + let range = NSRange(location: match.range(at: 1).location, + length: match.range(at: 2).location - match.range(at: 1).location) formatText(attributedString, range: range, level: level) } } diff --git a/MarkdownKit/Classes/Protocols/MarkdownStyle.swift b/MarkdownKit/Classes/Protocols/MarkdownStyle.swift index 199995b..c418f5f 100644 --- a/MarkdownKit/Classes/Protocols/MarkdownStyle.swift +++ b/MarkdownKit/Classes/Protocols/MarkdownStyle.swift @@ -13,20 +13,20 @@ public protocol MarkdownStyle { var font: UIFont? { get } var color: UIColor? { get } - var attributes: [String: AnyObject] { get } + var attributes: [NSAttributedStringKey: AnyObject] { get } } public extension MarkdownStyle { - var attributes: [String: AnyObject] { - var attributes = [String: AnyObject]() + var attributes: [NSAttributedStringKey: AnyObject] { + var attributes = [NSAttributedStringKey: AnyObject]() if let font = font { - attributes[NSFontAttributeName] = font + attributes[NSAttributedStringKey.font] = font } if let color = color { - attributes[NSForegroundColorAttributeName] = color + attributes[NSAttributedStringKey.foregroundColor] = color } return attributes } -} \ No newline at end of file +} From a09c9e6bb6e7caf776fd42089fb0065e06ea2f1d Mon Sep 17 00:00:00 2001 From: "J.J. Castro" Date: Wed, 13 Sep 2017 22:29:54 -0500 Subject: [PATCH 2/4] Redo header font-sizing --- .DS_Store | Bin 6148 -> 8196 bytes MarkdownKit/.DS_Store | Bin 6148 -> 6148 bytes MarkdownKit/Classes/.DS_Store | Bin 6148 -> 6148 bytes .../Classes/Elements/MarkdownHeader.swift | 4 ++-- 4 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store index e66559ec4c4568ff078c586401dcf55ec4b1c97f..86db42acf22836b4a9af694474b1648d348638cf 100644 GIT binary patch literal 8196 zcmeHMTWl0n82Kg;~!kYQc_`h;%!aQmM!fQP0{i8_U5K& z>*ltJ3C32hjX%;onmuuH{M5wh^L#wCF!&1y)QJ0;`U15o3|D;7uubk-!NhcmogyQl z>2gM{&tzm-wY)sMtEYFj+&7}s7HP13IoGf)XRn@j2uG9}htk!Zv912R&h~CBOx`xle%mp4n0>>pe%$4{IjZ6Pj-7Wqyj=IdXgeK!v=N99Tk+OR;-RZuzq7p`@@N@=^ABatz0Ls8Y&u&kv8?glA*a{`&1{R zTbf}V*-!7%a*ZbqJuj`qCTYM@v-)&x{XJ{$y)PWT-MSoQxR5rE6%6-;5@SsC(GZSF z$|ZJCqsQ58YdoUnX~GTRM#c_sd1qdyT8QNh;U-B@*?>b&EkbOP`x4c(>E1|`_kRyXcQT=$O>7gv;Q;AJ;>xTOy5rq>` z+^%b++Yn6@ar|;w=C~YD78B!zc1xQqD^)Zlg!Z9rq+LSf7uxM%(t@w6 zZj8uGS|}oa0axKW_?0Mp6aK;_SdI1AK;+$s?YNz&o5U{MiGBD4rf>iU@i2}Oi8Dmw zEZTSs^F-xScp4}1X?zA>z_Uc;m+)o0Ktz5OU&Gh&O`O8Fh|-tw3Q_t4qV$(U=xcc0 zCu*6%y|)q=zpqT-Vk&Q$wsnLoxVHp*KnI7my8=zr3~!r9;wf4ra>f|2JXZRU{x}e?4Tzr zFP^tQBtL6M=^CYr7j8Ex&~u^6JB|~2$8o}$KMbiIB~$K`@NrTgNvQnm9|Gq27CojijS0?$%1x)5K(ZLz{YCcRnG9gS b$Oxes_@Ok6nzdPl`7z7H2E)zl9Dn%%6_p@Q delta 187 zcmZoMXffEJ$t3eDsURn_xWvHVCL zoSBlElvos=nNpGwFCZFFlvAvkp;C~ixw|gx@`H1BgYuPfRPbGGYCUz7i_@% diff --git a/MarkdownKit/Classes/Elements/MarkdownHeader.swift b/MarkdownKit/Classes/Elements/MarkdownHeader.swift index ddf0de9..f4a3b00 100644 --- a/MarkdownKit/Classes/Elements/MarkdownHeader.swift +++ b/MarkdownKit/Classes/Elements/MarkdownHeader.swift @@ -37,8 +37,8 @@ open class MarkdownHeader: MarkdownLevelElement { open func attributesForLevel(_ level: Int) -> [NSAttributedStringKey: AnyObject] { var attributes = self.attributes if let font = font { - let headerFontSize: CGFloat = font.pointSize + (CGFloat(level) * CGFloat(fontIncrease)) - attributes[NSAttributedStringKey.font] = font.withSize(headerFontSize) + let headerFontSize: CGFloat = font.pointSize + 4 + (-1 * CGFloat(level) * CGFloat(fontIncrease)) + attributes[NSAttributedStringKey.font] = font.withSize(headerFontSize).bold() } return attributes } From f7e8550d419ba530dbbb84799903204cd7d4347b Mon Sep 17 00:00:00 2001 From: "J.J. Castro" Date: Wed, 13 Sep 2017 22:41:13 -0500 Subject: [PATCH 3/4] More iOS 11 cleanup --- .DS_Store | Bin 8196 -> 8196 bytes MarkdownKit/Classes/.DS_Store | Bin 6148 -> 6148 bytes .../Classes/Extensions/String+UTF16.swift | 3 +-- 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store index 86db42acf22836b4a9af694474b1648d348638cf..e558ae490830566e56d21231ddea2fe24ef736f5 100644 GIT binary patch delta 39 lcmZp1XmQx!EzFb{u-RAmI1`Yb>?`cNIZ|vlJA%EM5dZ_O45|PC delta 39 lcmZp1XmQx!EzA`AV6(6AaV8)=*;m+kbEMdAb_9DhBLF3e4o(07 diff --git a/MarkdownKit/Classes/.DS_Store b/MarkdownKit/Classes/.DS_Store index b951b8efeb119e32d2c259e31bdc59927f63f685..99848330c2ae65da9e5598b377eb2ee4aabc2e30 100644 GIT binary patch delta 47 zcmZoMXfc@J&nU1lU^g?Pz~n*}klO6 Ct`5@x diff --git a/MarkdownKit/Classes/Extensions/String+UTF16.swift b/MarkdownKit/Classes/Extensions/String+UTF16.swift index 9080afe..ab69fb9 100644 --- a/MarkdownKit/Classes/Extensions/String+UTF16.swift +++ b/MarkdownKit/Classes/Extensions/String+UTF16.swift @@ -25,8 +25,7 @@ extension String { stride(from: 0, to: characters.count, by: 4).forEach { let startIndex = characters.index(characters.startIndex, offsetBy: $0) let endIndex = characters.index(characters.startIndex, offsetBy: $0 + 4) - let hex4 = substring(with: startIndex.. Date: Thu, 20 Sep 2018 14:32:35 +0200 Subject: [PATCH 4/4] swift 4.2 changes --- MarkdownKit/Classes/Elements/MarkdownHeader.swift | 4 ++-- MarkdownKit/Classes/Elements/MarkdownLink.swift | 2 +- MarkdownKit/Classes/Extensions/UIFont+Traits.swift | 4 ++-- MarkdownKit/Classes/MarkdownParser.swift | 2 +- .../Classes/Protocols/MarkdownLevelElement.swift | 4 ++-- MarkdownKit/Classes/Protocols/MarkdownStyle.swift | 10 +++++----- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/MarkdownKit/Classes/Elements/MarkdownHeader.swift b/MarkdownKit/Classes/Elements/MarkdownHeader.swift index f4a3b00..eeb0bd8 100644 --- a/MarkdownKit/Classes/Elements/MarkdownHeader.swift +++ b/MarkdownKit/Classes/Elements/MarkdownHeader.swift @@ -34,11 +34,11 @@ open class MarkdownHeader: MarkdownLevelElement { attributedString.deleteCharacters(in: range) } - open func attributesForLevel(_ level: Int) -> [NSAttributedStringKey: AnyObject] { + open func attributesForLevel(_ level: Int) -> [NSAttributedString.Key: AnyObject] { var attributes = self.attributes if let font = font { let headerFontSize: CGFloat = font.pointSize + 4 + (-1 * CGFloat(level) * CGFloat(fontIncrease)) - attributes[NSAttributedStringKey.font] = font.withSize(headerFontSize).bold() + attributes[NSAttributedString.Key.font] = font.withSize(headerFontSize).bold() } return attributes } diff --git a/MarkdownKit/Classes/Elements/MarkdownLink.swift b/MarkdownKit/Classes/Elements/MarkdownLink.swift index 3799412..aef0274 100644 --- a/MarkdownKit/Classes/Elements/MarkdownLink.swift +++ b/MarkdownKit/Classes/Elements/MarkdownLink.swift @@ -36,7 +36,7 @@ open class MarkdownLink: MarkdownLinkElement { return } guard let url = URL(string: link) ?? URL(string: encodedLink) else { return } - attributedString.addAttribute(NSAttributedStringKey.link, value: url, range: range) + attributedString.addAttribute(NSAttributedString.Key.link, value: url, range: range) } open func match(_ match: NSTextCheckingResult, attributedString: NSMutableAttributedString) { diff --git a/MarkdownKit/Classes/Extensions/UIFont+Traits.swift b/MarkdownKit/Classes/Extensions/UIFont+Traits.swift index 07b81c1..9b779a0 100644 --- a/MarkdownKit/Classes/Extensions/UIFont+Traits.swift +++ b/MarkdownKit/Classes/Extensions/UIFont+Traits.swift @@ -9,9 +9,9 @@ import UIKit extension UIFont { - func withTraits(_ traits: UIFontDescriptorSymbolicTraits...) -> UIFont { + func withTraits(_ traits: UIFontDescriptor.SymbolicTraits...) -> UIFont { let descriptor = fontDescriptor - .withSymbolicTraits(UIFontDescriptorSymbolicTraits(traits)) + .withSymbolicTraits(UIFontDescriptor.SymbolicTraits(traits)) return UIFont(descriptor: descriptor!, size: 0) } diff --git a/MarkdownKit/Classes/MarkdownParser.swift b/MarkdownKit/Classes/MarkdownParser.swift index fb77949..5aac61d 100644 --- a/MarkdownKit/Classes/MarkdownParser.swift +++ b/MarkdownKit/Classes/MarkdownParser.swift @@ -80,7 +80,7 @@ open class MarkdownParser { open func parse(_ markdown: NSAttributedString) -> NSAttributedString { let attributedString = NSMutableAttributedString(attributedString: markdown) - attributedString.addAttribute(NSAttributedStringKey.font, value: font, + attributedString.addAttribute(NSAttributedString.Key.font, value: font, range: NSRange(location: 0, length: attributedString.length)) var elements: [MarkdownElement] = escapingElements elements.append(contentsOf: defaultElements) diff --git a/MarkdownKit/Classes/Protocols/MarkdownLevelElement.swift b/MarkdownKit/Classes/Protocols/MarkdownLevelElement.swift index 4c83eb7..f92c285 100644 --- a/MarkdownKit/Classes/Protocols/MarkdownLevelElement.swift +++ b/MarkdownKit/Classes/Protocols/MarkdownLevelElement.swift @@ -17,7 +17,7 @@ public protocol MarkdownLevelElement: MarkdownElement, MarkdownStyle { func formatText(_ attributedString: NSMutableAttributedString, range: NSRange, level: Int) func addAttributes(_ attributedString: NSMutableAttributedString, range: NSRange, level: Int) - func attributesForLevel(_ level: Int) -> [NSAttributedStringKey: AnyObject] + func attributesForLevel(_ level: Int) -> [NSAttributedString.Key: AnyObject] } public extension MarkdownLevelElement { @@ -31,7 +31,7 @@ public extension MarkdownLevelElement { attributedString.addAttributes(attributesForLevel(level - 1), range: range) } - func attributesForLevel(_ level: Int) -> [NSAttributedStringKey: AnyObject] { + func attributesForLevel(_ level: Int) -> [NSAttributedString.Key: AnyObject] { return self.attributes } diff --git a/MarkdownKit/Classes/Protocols/MarkdownStyle.swift b/MarkdownKit/Classes/Protocols/MarkdownStyle.swift index c418f5f..f7266fc 100644 --- a/MarkdownKit/Classes/Protocols/MarkdownStyle.swift +++ b/MarkdownKit/Classes/Protocols/MarkdownStyle.swift @@ -13,18 +13,18 @@ public protocol MarkdownStyle { var font: UIFont? { get } var color: UIColor? { get } - var attributes: [NSAttributedStringKey: AnyObject] { get } + var attributes: [NSAttributedString.Key: AnyObject] { get } } public extension MarkdownStyle { - var attributes: [NSAttributedStringKey: AnyObject] { - var attributes = [NSAttributedStringKey: AnyObject]() + var attributes: [NSAttributedString.Key: AnyObject] { + var attributes = [NSAttributedString.Key: AnyObject]() if let font = font { - attributes[NSAttributedStringKey.font] = font + attributes[NSAttributedString.Key.font] = font } if let color = color { - attributes[NSAttributedStringKey.foregroundColor] = color + attributes[NSAttributedString.Key.foregroundColor] = color } return attributes }