Skip to content

Commit

Permalink
Swift 3.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanbruel committed Sep 15, 2016
1 parent b39a8d0 commit 7f013fa
Show file tree
Hide file tree
Showing 134 changed files with 393 additions and 9,681 deletions.
14 changes: 8 additions & 6 deletions Example/MarkdownKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
692A91EA158B568FC13AA8EE /* Pods_MarkdownKit_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98F80248942349385F75D6C4 /* Pods_MarkdownKit_Example.framework */; };
C8B5D13471A29A0870015CD7 /* Pods_MarkdownKit_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7F6F1E950CA46794B56C014 /* Pods_MarkdownKit_Tests.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -44,7 +43,6 @@
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
607FACE51AFB9204008FA782 /* MarkdownKit_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MarkdownKit_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
6E64BE9BDDB475BDDD3A0853 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
7EDB647DC3B29FA018ECBA8C /* Pods-MarkdownKit_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MarkdownKit_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-MarkdownKit_Example/Pods-MarkdownKit_Example.release.xcconfig"; sourceTree = "<group>"; };
90E244442C683C9DF202089B /* Pods-MarkdownKit_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MarkdownKit_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MarkdownKit_Example/Pods-MarkdownKit_Example.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -133,7 +131,6 @@
607FACE81AFB9204008FA782 /* Tests */ = {
isa = PBXGroup;
children = (
607FACEB1AFB9204008FA782 /* Tests.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
path = Tests;
Expand Down Expand Up @@ -224,9 +221,11 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
Expand Down Expand Up @@ -284,7 +283,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
42BDD7DFF90B8757A31CA14D /* [CP] Embed Pods Frameworks */ = {
Expand Down Expand Up @@ -344,7 +343,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
F561AFE7D8587BF142E6492A /* [CP] Embed Pods Frameworks */ = {
Expand Down Expand Up @@ -380,7 +379,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -506,6 +504,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -519,6 +518,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -535,6 +535,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -547,6 +548,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
12 changes: 6 additions & 6 deletions Example/MarkdownKit/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: 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:.
}

Expand Down
8 changes: 4 additions & 4 deletions Example/MarkdownKit/MarkdownSubreddit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import MarkdownKit

class MarkdownSubreddit: MarkdownLink {

private static let regex = "(^|\\s|\\W)(/?r/(\\w+)/?)"
fileprivate static let regex = "(^|\\s|\\W)(/?r/(\\w+)/?)"

override var regex: String {
return MarkdownSubreddit.regex
}

override func match(match: NSTextCheckingResult,
override func match(_ match: NSTextCheckingResult,
attributedString: NSMutableAttributedString) {
let subredditName = attributedString.attributedSubstringFromRange(match.rangeAtIndex(3)).string
let subredditName = attributedString.attributedSubstring(from: match.rangeAt(3)).string
let linkURLString = "http://reddit.com/r/\(subredditName)"
formatText(attributedString, range: match.range, link: linkURLString)
addAttributes(attributedString, range: match.range, link: linkURLString)
}

}
}
26 changes: 13 additions & 13 deletions Example/MarkdownKit/String+HTMLDecode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ extension String {
// Unicode character, e.g.
// decodeNumeric("64", 10) --> "@"
// decodeNumeric("20ac", 16) --> "€"
func decodeNumeric(string: String, base: Int32) -> Character? {
func decodeNumeric(_ string: String, base: Int32) -> Character? {
let code = UInt32(strtoul(string, nil, base))
return Character(UnicodeScalar(code))
return Character(UnicodeScalar(code)!)
}

// Decode the HTML character entity to the corresponding
Expand All @@ -48,12 +48,12 @@ extension String {
// decode("&#x20ac;") --> "€"
// decode("&lt;") --> "<"
// decode("&foo;") --> nil
func decode(entity: String) -> Character? {
func decode(_ entity: String) -> Character? {

if entity.hasPrefix("&#x") || entity.hasPrefix("&#X") {
return decodeNumeric(entity.substringFromIndex(entity.startIndex.advancedBy(3)), base: 16)
return decodeNumeric(entity.substring(from: entity.characters.index(entity.startIndex, offsetBy: 3)), base: 16)
} else if entity.hasPrefix("&#") {
return decodeNumeric(entity.substringFromIndex(entity.startIndex.advancedBy(2)), base: 10)
return decodeNumeric(entity.substring(from: entity.characters.index(entity.startIndex, offsetBy: 2)), base: 10)
} else {
return characterEntities[entity]
}
Expand All @@ -65,29 +65,29 @@ extension String {
var position = startIndex

// Find the next '&' and copy the characters preceding it to `result`:
while let ampRange = self.rangeOfString("&", range: position ..< endIndex) {
result.appendContentsOf(self[position ..< ampRange.startIndex])
position = ampRange.startIndex
while let ampRange = self.range(of: "&", range: position ..< endIndex) {
result.append(self[position ..< ampRange.lowerBound])
position = ampRange.lowerBound

// Find the next ';' and copy everything from '&' to ';' into `entity`
if let semiRange = self.rangeOfString(";", range: position ..< endIndex) {
let entity = self[position ..< semiRange.endIndex]
position = semiRange.endIndex
if let semiRange = self.range(of: ";", range: position ..< endIndex) {
let entity = self[position ..< semiRange.upperBound]
position = semiRange.upperBound

if let decoded = decode(entity) {
// Replace by decoded character:
result.append(decoded)
} else {
// Invalid entity, copy verbatim:
result.appendContentsOf(entity)
result.append(entity)
}
} else {
// No matching ';'.
break
}
}
// Copy remaining characters to `result`:
result.appendContentsOf(self[position ..< endIndex])
result.append(self[position ..< endIndex])
return result
}
}
10 changes: 5 additions & 5 deletions Example/MarkdownKit/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import MarkdownKit

class ViewController: UIViewController {

@IBOutlet private weak var textView: UITextView! {
@IBOutlet fileprivate weak var textView: UITextView! {
didSet {
textView.delegate = self
}
}
private let markdownParser = MarkdownParser()
fileprivate let markdownParser = MarkdownParser()

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -34,9 +34,9 @@ class ViewController: UIViewController {

extension ViewController: UITextViewDelegate {

func textView(textView: UITextView, shouldInteractWithURL URL: NSURL,
inRange characterRange: NSRange) -> Bool {
UIApplication.sharedApplication().openURL(URL)
func textView(_ textView: UITextView, shouldInteractWith URL: URL,
in characterRange: NSRange) -> Bool {
UIApplication.shared.openURL(URL)
return true
}

Expand Down
2 changes: 0 additions & 2 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ target 'MarkdownKit_Example' do
target 'MarkdownKit_Tests' do
inherit! :search_paths

pod 'Quick', '~> 0.8'
pod 'Nimble', '~> 3.0'
end
end
14 changes: 4 additions & 10 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
PODS:
- MarkdownKit (1.0.3)
- Nimble (3.2.0)
- Quick (0.9.3)
- MarkdownKit (1.1.0)

DEPENDENCIES:
- MarkdownKit (from `../`)
- Nimble (~> 3.0)
- Quick (~> 0.8)

EXTERNAL SOURCES:
MarkdownKit:
:path: "../"

SPEC CHECKSUMS:
MarkdownKit: 82e36166884b3afae588528f38abab321d18cfcc
Nimble: 703854335d181df169bbca9c97117b5cf8c47c1d
Quick: 13a2a2b19a5d8e3ed4fd0c36ee46597fd77ebf71
MarkdownKit: 60d759cd14169144e4b159cb34312f8a5dd77570

PODFILE CHECKSUM: 37332923ac62269b229836ec80bf572c6603114d
PODFILE CHECKSUM: ccadfd166c0ec570bf4db2bbf94766db628792f3

COCOAPODS: 1.0.1
COCOAPODS: 1.1.0.rc.2
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/MarkdownKit.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7f013fa

Please sign in to comment.