Commit 4832bede authored by Aral Balkan's avatar Aral Balkan

Update to Swift 3

parent 0f34bdc6
git "git@source.ind.ie:project/handle.git" "swift-2.3"
\ No newline at end of file
git "git@source.ind.ie:project/handle.git" "swift-3"
\ No newline at end of file
git "git@source.ind.ie:project/handle.git" "ad0951a20afdd75e5a8f7cc1fc0ca14cd533df64"
git "git@source.ind.ie:project/handle.git" "c187932824dde0306981aa9184f8fea5abb0d645"
......@@ -329,7 +329,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -347,7 +347,7 @@
PRODUCT_BUNDLE_IDENTIFIER = ind.ie.Delay;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
......
......@@ -36,7 +36,10 @@ import Foundation
// MARK: Public API
public func delay(delay:Double, block:dispatch_block_t) -> CancellableDelayedCommand
// Swift 3 (to replace dispatch_block_t)
public typealias Block = (Void) -> Void
public func delay(_ delay:Double, block:Block) -> CancellableDelayedCommand
{
return CancellableDelayedCommand(delay: delay, block: block)
}
......@@ -47,12 +50,12 @@ public class CancellableDelayedCommand
{
public var executed:Bool
var originalBlock:dispatch_block_t
var delayedBlock:dispatch_block_t?
var originalBlock:Block
var delayedBlock:Block?
var cancelled:Bool
var delay:Double
public init(delay:Double, block:dispatch_block_t)
public init(delay:Double, block:Block)
{
self.delay = delay
self.originalBlock = block
......@@ -79,7 +82,7 @@ public class CancellableDelayedCommand
if !self.cancelled
{
// println("\(self): delayed block about to dispatch!")
dispatch_async(dispatch_get_main_queue(), block)
DispatchQueue.main.async(execute: block)
self.executed = true
}
// else
......@@ -90,7 +93,7 @@ public class CancellableDelayedCommand
}
// Set up the delayed dispatch.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue())
DispatchQueue.main.after(when: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC))
{
dispatch_block_t in
......
......@@ -316,7 +316,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.DelayDemo-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -332,7 +332,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.DelayDemo-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
......
......@@ -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: [NSObject: AnyObject]?) -> 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:.
}
......
......@@ -42,10 +42,10 @@ class IOSViewController: UIViewController, UITextFieldDelegate
// MARK: - View lifecycle.
//
override func viewWillAppear(animated:Bool)
override func viewWillAppear(_ animated:Bool)
{
super.viewWillAppear(animated)
textDidChangeNotificationHandler = handle(UITextFieldTextDidChangeNotification, from:throttledTextField)
textDidChangeNotificationHandler = handle(NSNotification.Name.UITextFieldTextDidChange.rawValue, from:throttledTextField)
{
/* with */ notification in
......@@ -55,50 +55,50 @@ class IOSViewController: UIViewController, UITextFieldDelegate
//
self.cancellableTextFieldLookupCommand = self.cancellableTextFieldLookupCommand?.reset() ?? delay(0.3)
{
let options: NSLinguisticTaggerOptions = [.OmitWhitespace, .OmitPunctuation, .JoinNames]
let schemes = NSLinguisticTagger.availableTagSchemesForLanguage("en")
let options: NSLinguisticTagger.Options = [.omitWhitespace, .omitPunctuation, .joinNames]
let schemes = NSLinguisticTagger.availableTagSchemes(forLanguage: "en")
let tagger = NSLinguisticTagger(tagSchemes: schemes, options: Int(options.rawValue))
guard let text = self.throttledTextField.text else { return }
tagger.string = text
var linguisticBreakdownOfText = ""
tagger.enumerateTagsInRange(NSMakeRange(0, (text as NSString).length), scheme: NSLinguisticTagSchemeNameTypeOrLexicalClass, options: options)
tagger.enumerateTags(in: NSMakeRange(0, (text as NSString).length), scheme: NSLinguisticTagSchemeNameTypeOrLexicalClass, options: options)
{
(tag, tokenRange, sentenceRange, _) in
let token = (text as NSString).substringWithRange(tokenRange)
let token = (text as NSString).substring(with: tokenRange)
linguisticBreakdownOfText += "\(token): \(tag)\n"
}
self.throttledTextView.text = linguisticBreakdownOfText
self.throttledTextView.font = UIFont.systemFontOfSize(24.0)
self.throttledTextView.font = UIFont.systemFont(ofSize: 24.0)
}
}
let keyboardVisibilityWillChangeHandler =
{
/* handle */ (notification:NSNotification!) -> Void in
/* handle */ (notification:Notification!) -> Void in
// print("Keyboard visibility will change: \(notification)")
if let
userInfo = notification.userInfo,
keyboardFrameBegin = userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue,
keyboardFrameEnd = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue,
animationDuration = userInfo[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue
keyboardFrameBegin = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue(),
keyboardFrameEnd = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue(),
animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue
{
let keyboardFrameBeginLocalRect = self.view.convertRect(keyboardFrameBegin, fromView: self.view.window)
let keyboardFrameEndLocalRect = self.view.convertRect(keyboardFrameEnd, fromView: self.view.window)
let keyboardFrameBeginLocalRect = self.view.convert(keyboardFrameBegin, from: self.view.window)
let keyboardFrameEndLocalRect = self.view.convert(keyboardFrameEnd, from: self.view.window)
let keyboardDeltaY = keyboardFrameEndLocalRect.origin.y - keyboardFrameBeginLocalRect.origin.y
self.stackViewTopToTopLayoutGuideBottomDistanceConstraint.constant += keyboardDeltaY
UIView.animateWithDuration(
animationDuration,
UIView.animate(
withDuration: animationDuration,
delay: 0.0,
options: .BeginFromCurrentState,
options: .beginFromCurrentState,
animations:
{
self.view.layoutIfNeeded()
......@@ -108,11 +108,11 @@ class IOSViewController: UIViewController, UITextFieldDelegate
}
}
keyboardWillShowHandler = keyboardWillShowHandler ?? handle(UIKeyboardWillShowNotification, with: keyboardVisibilityWillChangeHandler)
keyboardWillHideHandler = keyboardWillHideHandler ?? handle(UIKeyboardWillHideNotification, with: keyboardVisibilityWillChangeHandler)
keyboardWillShowHandler = keyboardWillShowHandler ?? handle(NSNotification.Name.UIKeyboardWillShow.rawValue, with: keyboardVisibilityWillChangeHandler)
keyboardWillHideHandler = keyboardWillHideHandler ?? handle(NSNotification.Name.UIKeyboardWillHide.rawValue, with: keyboardVisibilityWillChangeHandler)
}
override func viewWillDisappear(animated:Bool)
override func viewWillDisappear(_ animated:Bool)
{
super.viewWillDisappear(animated)
destroyNotificationHandler(&textDidChangeNotificationHandler)
......@@ -126,7 +126,7 @@ class IOSViewController: UIViewController, UITextFieldDelegate
// MARK: - Actions
//
@IBAction func threeSecondsButtonAction(sender: UIButton)
@IBAction func threeSecondsButtonAction(_ sender: UIButton)
{
threeSecondDelayLabel.text = "Waiting…"
delay(3)
......@@ -136,7 +136,7 @@ class IOSViewController: UIViewController, UITextFieldDelegate
}
@IBAction func fiveSecondsButtonAction(sender: UIButton)
@IBAction func fiveSecondsButtonAction(_ sender: UIButton)
{
fiveSecondDelayLabel.text = "Waiting…"
......@@ -147,7 +147,7 @@ class IOSViewController: UIViewController, UITextFieldDelegate
}
@IBAction func cancelFiveSecondDelayButtonAction(sender: UIButton)
@IBAction func cancelFiveSecondDelayButtonAction(_ sender: UIButton)
{
// Note: you can also check if a command had been cancelled
// by examining its .cancelled property (Bool).
......@@ -169,7 +169,7 @@ class IOSViewController: UIViewController, UITextFieldDelegate
}
// MARK: - UITextFieldDelegate methods
func textFieldShouldReturn(textField: UITextField) -> Bool
func textFieldShouldReturn(_ textField: UITextField) -> Bool
{
throttledTextField.resignFirstResponder()
return true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment