From b51f13054c3ea20093c59c30697e0f57e2286733 Mon Sep 17 00:00:00 2001 From: Simon Fairbairn Date: Mon, 29 Aug 2016 15:05:04 +0200 Subject: [PATCH] Fixing for Swift 3 --- .swift-version | 1 + SwiftyMarkdown.playground/Contents.swift | 16 +- SwiftyMarkdown.xcodeproj/project.pbxproj | 14 +- SwiftyMarkdown/Info.plist | 2 +- SwiftyMarkdown/SwiftyMarkdown.swift | 225 +++++++++--------- .../project.pbxproj | 16 +- .../SwiftyMarkdownExample/AppDelegate.swift | 12 +- .../ViewController.swift | 8 +- .../SwiftyMarkdownExampleTests.swift | 2 +- SwiftyMarkdownTests/Info.plist | 2 +- 10 files changed, 163 insertions(+), 135 deletions(-) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..9f55b2c --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +3.0 diff --git a/SwiftyMarkdown.playground/Contents.swift b/SwiftyMarkdown.playground/Contents.swift index 2c4edc7..b8e4e85 100644 --- a/SwiftyMarkdown.playground/Contents.swift +++ b/SwiftyMarkdown.playground/Contents.swift @@ -9,6 +9,15 @@ XCPlaygroundPage.currentPage.liveView = containerView let label = UITextView(frame: containerView.frame) containerView.addSubview(label) +var foundCharacters : String = "" +var matchedCharacters : String = "\\Some string ''\\" +if let hasRange = matchedCharacters.range(of: "\\") { + + let newRange = hasRange.lowerBound..CFBundlePackageType FMWK CFBundleShortVersionString - 0.2.2 + 0.2.3 CFBundleSignature ???? CFBundleVersion diff --git a/SwiftyMarkdown/SwiftyMarkdown.swift b/SwiftyMarkdown/SwiftyMarkdown.swift index 6bda863..1169a60 100644 --- a/SwiftyMarkdown/SwiftyMarkdown.swift +++ b/SwiftyMarkdown/SwiftyMarkdown.swift @@ -21,78 +21,78 @@ A struct defining the styles that can be applied to the parsed Markdown. The `fo If that is not set, then the system default will be used. */ public struct BasicStyles : FontProperties { - public var fontName : String? = UIFont.preferredFontForTextStyle(UIFontTextStyleBody).fontName - public var color = UIColor.blackColor() + public var fontName : String? = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body).fontName + public var color = UIColor.black } enum LineType : Int { - case H1, H2, H3, H4, H5, H6, Body + case h1, h2, h3, h4, h5, h6, body } enum LineStyle : Int { - case None - case Italic - case Bold - case Code - case Link + case none + case italic + case bold + case code + case link - static func styleFromString(string : String ) -> LineStyle { + static func styleFromString(_ string : String ) -> LineStyle { if string == "**" || string == "__" { - return .Bold + return .bold } else if string == "*" || string == "_" { - return .Italic + return .italic } else if string == "`" { - return .Code + return .code } else if string == "[" { - return .Link + return .link } else { - return .None + return .none } } } /// A class that takes a [Markdown](https://daringfireball.net/projects/markdown/) string or file and returns an NSAttributedString with the applied styles. Supports Dynamic Type. -public class SwiftyMarkdown { +open class SwiftyMarkdown { /// The styles to apply to any H1 headers found in the Markdown - public var h1 = BasicStyles() + open var h1 = BasicStyles() /// The styles to apply to any H2 headers found in the Markdown - public var h2 = BasicStyles() + open var h2 = BasicStyles() /// The styles to apply to any H3 headers found in the Markdown - public var h3 = BasicStyles() + open var h3 = BasicStyles() /// The styles to apply to any H4 headers found in the Markdown - public var h4 = BasicStyles() + open var h4 = BasicStyles() /// The styles to apply to any H5 headers found in the Markdown - public var h5 = BasicStyles() + open var h5 = BasicStyles() /// The styles to apply to any H6 headers found in the Markdown - public var h6 = BasicStyles() + open var h6 = BasicStyles() /// The default body styles. These are the base styles and will be used for e.g. headers if no other styles override them. - public var body = BasicStyles() + open var body = BasicStyles() /// The styles to apply to any links found in the Markdown - public var link = BasicStyles() + open var link = BasicStyles() /// The styles to apply to any bold text found in the Markdown - public var bold = BasicStyles() + open var bold = BasicStyles() /// The styles to apply to any italic text found in the Markdown - public var italic = BasicStyles() + open var italic = BasicStyles() /// The styles to apply to any code blocks or inline code text found in the Markdown - public var code = BasicStyles() + open var code = BasicStyles() - var currentType : LineType = .Body + var currentType : LineType = .body let string : String - let instructionSet = NSCharacterSet(charactersInString: "[\\*_`") + let instructionSet = CharacterSet(charactersIn: "[\\*_`") /** @@ -111,10 +111,10 @@ public class SwiftyMarkdown { - returns: An initialized SwiftyMarkdown object, or nil if the string couldn't be read */ - public init?(url : NSURL ) { + public init?(url : URL ) { do { - self.string = try NSString(contentsOfURL: url, encoding: NSUTF8StringEncoding) as String + self.string = try NSString(contentsOf: url, encoding: String.Encoding.utf8.rawValue) as String } catch { self.string = "" @@ -128,10 +128,10 @@ public class SwiftyMarkdown { - returns: An NSAttributedString with the styles applied */ - public func attributedString() -> NSAttributedString { + open func attributedString() -> NSAttributedString { let attributedString = NSMutableAttributedString(string: "") - let lines = self.string.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) + let lines = self.string.components(separatedBy: CharacterSet.newlines) var lineCount = 0 @@ -147,15 +147,15 @@ public class SwiftyMarkdown { var line = theLine for heading in headings { - if let range = line.rangeOfString(heading) where range.startIndex == line.startIndex { + if let range = line.range(of: heading) , range.lowerBound == line.startIndex { - let startHeadingString = line.stringByReplacingCharactersInRange(range, withString: "") + let startHeadingString = line.replacingCharacters(in: range, with: "") // Remove ending - let endHeadingString = heading.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) - line = startHeadingString.stringByReplacingOccurrencesOfString(endHeadingString, withString: "").stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) + let endHeadingString = heading.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + line = startHeadingString.replacingOccurrences(of: endHeadingString, with: "").trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) - currentType = LineType(rawValue: headings.indexOf(heading)!)! + currentType = LineType(rawValue: headings.index(of: heading)!)! // We found a heading so break out of the inner loop break @@ -166,16 +166,16 @@ public class SwiftyMarkdown { if lineCount < lines.count { let nextLine = lines[lineCount] - if let range = nextLine.rangeOfString("=") where range.startIndex == nextLine.startIndex { + if let range = nextLine.range(of: "=") , range.lowerBound == nextLine.startIndex { // Make H1 - currentType = .H1 + currentType = .h1 // We need to skip the next line skipLine = true } - if let range = nextLine.rangeOfString("-") where range.startIndex == nextLine.startIndex { + if let range = nextLine.range(of: "-") , range.lowerBound == nextLine.startIndex { // Make H2 - currentType = .H2 + currentType = .h2 // We need to skip the next line skipLine = true } @@ -185,55 +185,55 @@ public class SwiftyMarkdown { if line.characters.count > 0 { // ...start scanning - let scanner = NSScanner(string: line) + let scanner = Scanner(string: line) // We want to be aware of spaces scanner.charactersToBeSkipped = nil - while !scanner.atEnd { + while !scanner.isAtEnd { var string : NSString? // Get all the characters up to the ones we are interested in - if scanner.scanUpToCharactersFromSet(instructionSet, intoString: &string) { + if scanner.scanUpToCharacters(from: instructionSet, into: &string) { if let hasString = string as? String { - let bodyString = attributedStringFromString(hasString, withStyle: .None) - attributedString.appendAttributedString(bodyString) + let bodyString = attributedStringFromString(hasString, withStyle: .none) + attributedString.append(bodyString) let location = scanner.scanLocation let matchedCharacters = tagFromScanner(scanner).foundCharacters // If the next string after the characters is a space, then add it to the final string and continue - let set = NSMutableCharacterSet.whitespaceCharacterSet() - set.formUnionWithCharacterSet(NSCharacterSet.punctuationCharacterSet()) - if scanner.scanUpToCharactersFromSet(set, intoString: nil) { + let set = NSMutableCharacterSet.whitespace() + set.formUnion(with: CharacterSet.punctuationCharacters) + if scanner.scanUpToCharacters(from: set as CharacterSet, into: nil) { scanner.scanLocation = location - attributedString.appendAttributedString(self.attributedStringFromScanner(scanner)) + attributedString.append(self.attributedStringFromScanner(scanner)) } else if matchedCharacters == "[" { scanner.scanLocation = location - attributedString.appendAttributedString(self.attributedStringFromScanner(scanner)) + attributedString.append(self.attributedStringFromScanner(scanner)) } else { - let charAtts = attributedStringFromString(matchedCharacters, withStyle: .None) - attributedString.appendAttributedString(charAtts) + let charAtts = attributedStringFromString(matchedCharacters, withStyle: .none) + attributedString.append(charAtts) } } } else { - attributedString.appendAttributedString(self.attributedStringFromScanner(scanner, atStartOfLine: true)) + attributedString.append(self.attributedStringFromScanner(scanner, atStartOfLine: true)) } } } // Append a new line character to the end of the processed line - attributedString.appendAttributedString(NSAttributedString(string: "\n")) - currentType = .Body + attributedString.append(NSAttributedString(string: "\n")) + currentType = .body } return attributedString } - func attributedStringFromScanner( scanner : NSScanner, atStartOfLine start : Bool = false) -> NSAttributedString { + func attributedStringFromScanner( _ scanner : Scanner, atStartOfLine start : Bool = false) -> NSAttributedString { var followingString : NSString? let results = self.tagFromScanner(scanner) @@ -241,73 +241,74 @@ public class SwiftyMarkdown { var style = LineStyle.styleFromString(results.foundCharacters) var attributes = [String : AnyObject]() - if style == .Link { + if style == .link { var linkText : NSString? var linkURL : NSString? - let linkCharacters = NSCharacterSet(charactersInString: "]()") + let linkCharacters = CharacterSet(charactersIn: "]()") - scanner.scanUpToCharactersFromSet(linkCharacters, intoString: &linkText) - scanner.scanCharactersFromSet(linkCharacters, intoString: nil) - scanner.scanUpToCharactersFromSet(linkCharacters, intoString: &linkURL) - scanner.scanCharactersFromSet(linkCharacters, intoString: nil) + scanner.scanUpToCharacters(from: linkCharacters, into: &linkText) + scanner.scanCharacters(from: linkCharacters, into: nil) + scanner.scanUpToCharacters(from: linkCharacters, into: &linkURL) + scanner.scanCharacters(from: linkCharacters, into: nil) - if let hasLink = linkText, hasURL = linkURL { - followingString = hasLink as String - attributes[NSLinkAttributeName] = hasURL as String + if let hasLink = linkText, let hasURL = linkURL { + followingString = hasLink + attributes[NSLinkAttributeName] = hasURL } else { - style = .None + style = .none } } else { - scanner.scanUpToCharactersFromSet(instructionSet, intoString: &followingString) + scanner.scanUpToCharacters(from: instructionSet, into: &followingString) } let attributedString = attributedStringFromString(results.escapedCharacters, withStyle: style).mutableCopy() as! NSMutableAttributedString if let hasString = followingString as? String { - let prefix = ( style == .Code && start ) ? "\t" : "" + let prefix = ( style == .code && start ) ? "\t" : "" let attString = attributedStringFromString(prefix + hasString, withStyle: style, attributes: attributes) - attributedString.appendAttributedString(attString) + attributedString.append(attString) } let suffix = self.tagFromScanner(scanner) - attributedString.appendAttributedString(attributedStringFromString(suffix.escapedCharacters, withStyle: style)) + attributedString.append(attributedStringFromString(suffix.escapedCharacters, withStyle: style)) return attributedString } - func tagFromScanner( scanner : NSScanner ) -> (foundCharacters : String, escapedCharacters : String) { + func tagFromScanner( _ scanner : Scanner ) -> (foundCharacters : String, escapedCharacters : String) { var matchedCharacters : String = "" var tempCharacters : NSString? // Scan the ones we are interested in - while scanner.scanCharactersFromSet(instructionSet, intoString: &tempCharacters) { + while scanner.scanCharacters(from: instructionSet, into: &tempCharacters) { if let chars = tempCharacters as? String { matchedCharacters = matchedCharacters + chars } } var foundCharacters : String = "" - while matchedCharacters.containsString("\\") { - if let hasRange = matchedCharacters.rangeOfString("\\") { + while matchedCharacters.contains("\\") { + if let hasRange = matchedCharacters.range(of: "\\") { - let newRange = hasRange.startIndex...hasRange.endIndex - foundCharacters = foundCharacters + matchedCharacters.substringWithRange(newRange) - - matchedCharacters.removeRange(newRange) + // FIXME: Possible error in range + let newRange = hasRange.lowerBound.. NSAttributedString { - let textStyle : String + func attributedStringFromString(_ string : String, withStyle style : LineStyle, attributes : [String : AnyObject] = [:] ) -> NSAttributedString { + let textStyle : UIFontTextStyle var fontName : String? var attributes = attributes @@ -315,57 +316,57 @@ public class SwiftyMarkdown { switch currentType { - case .H1: + case .h1: fontName = h1.fontName if #available(iOS 9, *) { - textStyle = UIFontTextStyleTitle1 + textStyle = UIFontTextStyle.title1 } else { - textStyle = UIFontTextStyleHeadline + textStyle = UIFontTextStyle.headline } attributes[NSForegroundColorAttributeName] = h1.color - case .H2: + case .h2: fontName = h2.fontName if #available(iOS 9, *) { - textStyle = UIFontTextStyleTitle2 + textStyle = UIFontTextStyle.title2 } else { - textStyle = UIFontTextStyleHeadline + textStyle = UIFontTextStyle.headline } attributes[NSForegroundColorAttributeName] = h2.color - case .H3: + case .h3: fontName = h3.fontName if #available(iOS 9, *) { - textStyle = UIFontTextStyleTitle2 + textStyle = UIFontTextStyle.title2 } else { - textStyle = UIFontTextStyleSubheadline + textStyle = UIFontTextStyle.subheadline } attributes[NSForegroundColorAttributeName] = h3.color - case .H4: + case .h4: fontName = h4.fontName - textStyle = UIFontTextStyleHeadline + textStyle = UIFontTextStyle.headline attributes[NSForegroundColorAttributeName] = h4.color - case .H5: + case .h5: fontName = h5.fontName - textStyle = UIFontTextStyleSubheadline + textStyle = UIFontTextStyle.subheadline attributes[NSForegroundColorAttributeName] = h5.color - case .H6: + case .h6: fontName = h6.fontName - textStyle = UIFontTextStyleFootnote + textStyle = UIFontTextStyle.footnote attributes[NSForegroundColorAttributeName] = h6.color default: fontName = body.fontName - textStyle = UIFontTextStyleBody + textStyle = UIFontTextStyle.body attributes[NSForegroundColorAttributeName] = body.color break } // Check for code - if style == .Code { + if style == .code { fontName = code.fontName attributes[NSForegroundColorAttributeName] = code.color } - if style == .Link { + if style == .link { fontName = link.fontName attributes[NSForegroundColorAttributeName] = link.color } @@ -377,25 +378,25 @@ public class SwiftyMarkdown { fontName = body.fontName } - let font = UIFont.preferredFontForTextStyle(textStyle) - let styleDescriptor = font.fontDescriptor() - let styleSize = styleDescriptor.fontAttributes()[UIFontDescriptorSizeAttribute] as? CGFloat ?? CGFloat(14) + let font = UIFont.preferredFont(forTextStyle: textStyle) + let styleDescriptor = font.fontDescriptor + let styleSize = styleDescriptor.fontAttributes[UIFontDescriptorSizeAttribute] as? CGFloat ?? CGFloat(14) var finalFont : UIFont - if let finalFontName = fontName, font = UIFont(name: finalFontName, size: styleSize) { + if let finalFontName = fontName, let font = UIFont(name: finalFontName, size: styleSize) { finalFont = font } else { - finalFont = UIFont.preferredFontForTextStyle(textStyle) + finalFont = UIFont.preferredFont(forTextStyle: textStyle) } - let finalFontDescriptor = finalFont.fontDescriptor() - if style == .Italic { - let italicDescriptor = finalFontDescriptor.fontDescriptorWithSymbolicTraits(.TraitItalic) - finalFont = UIFont(descriptor: italicDescriptor, size: styleSize) + let finalFontDescriptor = finalFont.fontDescriptor + if style == .italic { + let italicDescriptor = finalFontDescriptor.withSymbolicTraits(.traitItalic) + finalFont = UIFont(descriptor: italicDescriptor!, size: styleSize) } - if style == .Bold { - let boldDescriptor = finalFontDescriptor.fontDescriptorWithSymbolicTraits(.TraitBold) - finalFont = UIFont(descriptor: boldDescriptor, size: styleSize) + if style == .bold { + let boldDescriptor = finalFontDescriptor.withSymbolicTraits(.traitBold) + finalFont = UIFont(descriptor: boldDescriptor!, size: styleSize) } diff --git a/SwiftyMarkdownExample/SwiftyMarkdownExample.xcodeproj/project.pbxproj b/SwiftyMarkdownExample/SwiftyMarkdownExample.xcodeproj/project.pbxproj index 3b2e7fa..c3dbedb 100644 --- a/SwiftyMarkdownExample/SwiftyMarkdownExample.xcodeproj/project.pbxproj +++ b/SwiftyMarkdownExample/SwiftyMarkdownExample.xcodeproj/project.pbxproj @@ -233,18 +233,21 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Voyage Travel Apps"; TargetAttributes = { F4CE98A71C8AEF7D00D735C1 = { CreatedOnToolsVersion = 7.2.1; + LastSwiftMigration = 0800; }; F4CE98BB1C8AEF7D00D735C1 = { CreatedOnToolsVersion = 7.2.1; + LastSwiftMigration = 0800; TestTargetID = F4CE98A71C8AEF7D00D735C1; }; F4CE98C61C8AEF7D00D735C1 = { CreatedOnToolsVersion = 7.2.1; + LastSwiftMigration = 0800; TestTargetID = F4CE98A71C8AEF7D00D735C1; }; }; @@ -394,8 +397,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -439,8 +444,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -459,6 +466,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -472,6 +480,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.voyagetravelapps.SwiftyMarkdownExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -483,6 +492,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.voyagetravelapps.SwiftyMarkdownExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -494,6 +504,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.voyagetravelapps.SwiftyMarkdownExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftyMarkdownExample.app/SwiftyMarkdownExample"; }; name = Debug; @@ -506,6 +517,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.voyagetravelapps.SwiftyMarkdownExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftyMarkdownExample.app/SwiftyMarkdownExample"; }; name = Release; @@ -517,6 +529,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.voyagetravelapps.SwiftyMarkdownExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_TARGET_NAME = SwiftyMarkdownExample; USES_XCTRUNNER = YES; }; @@ -529,6 +542,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.voyagetravelapps.SwiftyMarkdownExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_TARGET_NAME = SwiftyMarkdownExample; USES_XCTRUNNER = YES; }; diff --git a/SwiftyMarkdownExample/SwiftyMarkdownExample/AppDelegate.swift b/SwiftyMarkdownExample/SwiftyMarkdownExample/AppDelegate.swift index 6da6ff4..778f14e 100644 --- a/SwiftyMarkdownExample/SwiftyMarkdownExample/AppDelegate.swift +++ b/SwiftyMarkdownExample/SwiftyMarkdownExample/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/SwiftyMarkdownExample/SwiftyMarkdownExample/ViewController.swift b/SwiftyMarkdownExample/SwiftyMarkdownExample/ViewController.swift index e441e1c..1499a51 100644 --- a/SwiftyMarkdownExample/SwiftyMarkdownExample/ViewController.swift +++ b/SwiftyMarkdownExample/SwiftyMarkdownExample/ViewController.swift @@ -17,10 +17,10 @@ class ViewController: UIViewController { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. - self.textView.dataDetectorTypes = UIDataDetectorTypes.All - if let url = NSBundle.mainBundle().URLForResource("example", withExtension: "md"), md = SwiftyMarkdown(url: url) { + self.textView.dataDetectorTypes = UIDataDetectorTypes.all + if let url = Bundle.main.url(forResource: "example", withExtension: "md"), let md = SwiftyMarkdown(url: url) { md.h2.fontName = "AvenirNextCondensed-Bold" - md.h2.color = UIColor.redColor() + md.h2.color = UIColor.red md.code.fontName = "CourierNewPSMT" self.textView.attributedText = md.attributedString() @@ -35,7 +35,5 @@ class ViewController: UIViewController { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } - - } diff --git a/SwiftyMarkdownExample/SwiftyMarkdownExampleTests/SwiftyMarkdownExampleTests.swift b/SwiftyMarkdownExample/SwiftyMarkdownExampleTests/SwiftyMarkdownExampleTests.swift index 9b722cf..e39301e 100644 --- a/SwiftyMarkdownExample/SwiftyMarkdownExampleTests/SwiftyMarkdownExampleTests.swift +++ b/SwiftyMarkdownExample/SwiftyMarkdownExampleTests/SwiftyMarkdownExampleTests.swift @@ -28,7 +28,7 @@ class SwiftyMarkdownExampleTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock { + self.measure { // Put the code you want to measure the time of here. } } diff --git a/SwiftyMarkdownTests/Info.plist b/SwiftyMarkdownTests/Info.plist index c1c66a1..5b44dc7 100644 --- a/SwiftyMarkdownTests/Info.plist +++ b/SwiftyMarkdownTests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 0.2.2 + 0.2.3 CFBundleSignature ???? CFBundleVersion