Commit 3dc91c33 authored by Aral Balkan's avatar Aral Balkan

Update to Swift 3

Also update the readme.
parents b2a75469 af78de10
git "git@source.ind.ie:project/handle.git" ~> 3.0
\ No newline at end of file
git "git@source.ind.ie:project/handle.git"
\ No newline at end of file
git "git@source.ind.ie:project/handle.git" "v3.0.0"
git "git@source.ind.ie:project/handle.git" "4.0.0"
......@@ -5,7 +5,7 @@
location = "group:DelayDemo-iOS/DelayDemo-iOS.xcodeproj">
</FileRef>
<FileRef
location = "group:DelayDemo-OSX/DelayDemo-OSX.xcodeproj">
location = "group:/Users/aral/Ind.ie/products/Delay/DelayDemo-OSX/DelayDemo-macOS.xcodeproj">
</FileRef>
<FileRef
location = "group:Delay/Delay.xcodeproj">
......
......@@ -151,6 +151,7 @@
TargetAttributes = {
A7C0EA8F1C234E5D00110179 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
A7C0EA991C234E5D00110179 = {
CreatedOnToolsVersion = 7.2;
......@@ -324,10 +325,12 @@
INFOPLIST_FILE = Delay/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = ind.ie.Delay;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -342,9 +345,11 @@
INFOPLIST_FILE = Delay/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = ind.ie.Delay;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......
......@@ -36,23 +36,26 @@ 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:@escaping Block) -> CancellableDelayedCommand
{
return CancellableDelayedCommand(delay: delay, block: block)
}
// MARK: - Class
public class CancellableDelayedCommand
open class CancellableDelayedCommand
{
public var executed:Bool
open 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:@escaping 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.asyncAfter(deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC))
{
dispatch_block_t in
......@@ -102,14 +105,14 @@ public class CancellableDelayedCommand
}
public func cancel()
open func cancel()
{
// println("\(self): Cancelling.")
cancelled = true
}
public func reset() -> CancellableDelayedCommand?
open func reset() -> CancellableDelayedCommand?
{
//
// Cancels this command and creates and returns a new one
......
......@@ -9,18 +9,16 @@
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
class AppDelegate: NSObject, NSApplicationDelegate
{
func applicationDidFinishLaunching(_ aNotification: Notification)
{
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification) {
func applicationWillTerminate(_ aNotification: Notification)
{
// Insert code here to tear down your application
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Delay - demonstration - OS X.
// Delay - demonstration - macOS.
//
// With thanks to Mattt Thompson’s write-up on NSLinguisticTagger
// (http://nshipster.com/nslinguistictagger/)
......@@ -16,7 +16,7 @@ import Handle
// MARK: - Class
class OSXViewController: NSViewController
class MacOSViewController: NSViewController
{
// MARK: - Outlets
......@@ -46,34 +46,34 @@ class OSXViewController: NSViewController
override func viewWillAppear()
{
textDidChangeNotificationHandler = handle(NSControlTextDidChangeNotification, from:throttledTextField)
textDidChangeNotificationHandler = handle(NSNotification.Name.NSControlTextDidChange.rawValue, from:throttledTextField)
{
/* with */ notification in
//
// Wait 0.3 seconds after the last keystroke to analyse the entered text and
// provide a linguistic breakdown of it.
//
self.cancellableTextFieldLookupCommand = self.cancellableTextFieldLookupCommand?.reset() ?? delay(0.3)
{
/* with */ notification in
let options: NSLinguisticTagger.Options = [.omitWhitespace, .omitPunctuation, .joinNames]
let schemes = NSLinguisticTagger.availableTagSchemes(forLanguage: "en")
let tagger = NSLinguisticTagger(tagSchemes: schemes, options: Int(options.rawValue))
let text = self.throttledTextField.stringValue
tagger.string = text
//
// Wait 0.3 seconds after the last keystroke to analyse the entered text and
// provide a linguistic breakdown of it.
//
self.cancellableTextFieldLookupCommand = self.cancellableTextFieldLookupCommand?.reset() ?? delay(0.3)
{
let options: NSLinguisticTaggerOptions = [.OmitWhitespace, .OmitPunctuation, .JoinNames]
let schemes = NSLinguisticTagger.availableTagSchemesForLanguage("en")
let tagger = NSLinguisticTagger(tagSchemes: schemes, options: Int(options.rawValue))
let text = self.throttledTextField.stringValue
tagger.string = text
var linguisticBreakdownOfText = ""
tagger.enumerateTagsInRange(NSMakeRange(0, (text as NSString).length), scheme: NSLinguisticTagSchemeNameTypeOrLexicalClass, options: options)
{
(tag, tokenRange, sentenceRange, _) in
let token = (text as NSString).substringWithRange(tokenRange)
linguisticBreakdownOfText += "\(token): \(tag)\n"
}
self.throttledTextView.string = linguisticBreakdownOfText
var linguisticBreakdownOfText = ""
tagger.enumerateTags(in: NSMakeRange(0, (text as NSString).length), scheme: NSLinguisticTagSchemeNameTypeOrLexicalClass, options: options)
{
(tag, tokenRange, sentenceRange, _) in
let token = (text as NSString).substring(with: tokenRange)
linguisticBreakdownOfText += "\(token): \(tag)\n"
}
self.throttledTextView.string = linguisticBreakdownOfText
}
}
}
......@@ -88,17 +88,17 @@ class OSXViewController: NSViewController
// MARK: - Actions
//
@IBAction func threeSecondsButtonAction(sender: NSButton)
@IBAction func threeSecondsButtonAction(_ sender: NSButton)
{
threeSecondDelayLabel.stringValue = "Waiting…"
delay(3)
_ = delay(3)
{
self.threeSecondDelayLabel.stringValue = "Done!"
}
}
@IBAction func fiveSecondsButtonAction(sender: NSButton)
@IBAction func fiveSecondsButtonAction(_ sender: NSButton)
{
fiveSecondDelayLabel.stringValue = "Waiting…"
......@@ -109,7 +109,7 @@ class OSXViewController: NSViewController
}
@IBAction func cancelFiveSecondDelayButtonAction(sender: NSButton)
@IBAction func cancelFiveSecondDelayButtonAction(_ sender: NSButton)
{
// Note: you can also check if a command had been cancelled
// by examining its .cancelled property (Bool).
......
......@@ -35,7 +35,7 @@
/* Begin PBXFileReference section */
A7394BDC1CA435C70096FF28 /* Delay.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Delay.framework; path = "$(CONFIGURATION_BUILD_DIR)/Delay.framework"; sourceTree = "<group>"; };
A787D4671C24811E00CDBF66 /* Handle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Handle.framework; path = ../Carthage/Build/Mac/Handle.framework; sourceTree = "<group>"; };
A7C0EB6A1C2441C800110179 /* DelayDemo-OSX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "DelayDemo-OSX.app"; sourceTree = BUILT_PRODUCTS_DIR; };
A7C0EB6A1C2441C800110179 /* DelayDemo-macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "DelayDemo-macOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
A7C0EB6D1C2441C800110179 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
A7C0EB6F1C2441C800110179 /* OSXViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSXViewController.swift; sourceTree = "<group>"; };
A7C0EB711C2441C800110179 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
......@@ -60,7 +60,7 @@
isa = PBXGroup;
children = (
A787D4671C24811E00CDBF66 /* Handle.framework */,
A7C0EB6C1C2441C800110179 /* DelayDemo-OSX */,
A7C0EB6C1C2441C800110179 /* DelayDemo-macOS */,
A7C0EB6B1C2441C800110179 /* Products */,
);
sourceTree = "<group>";
......@@ -68,12 +68,12 @@
A7C0EB6B1C2441C800110179 /* Products */ = {
isa = PBXGroup;
children = (
A7C0EB6A1C2441C800110179 /* DelayDemo-OSX.app */,
A7C0EB6A1C2441C800110179 /* DelayDemo-macOS.app */,
);
name = Products;
sourceTree = "<group>";
};
A7C0EB6C1C2441C800110179 /* DelayDemo-OSX */ = {
A7C0EB6C1C2441C800110179 /* DelayDemo-macOS */ = {
isa = PBXGroup;
children = (
A7C0EB6D1C2441C800110179 /* AppDelegate.swift */,
......@@ -82,15 +82,16 @@
A7C0EB731C2441C800110179 /* Main.storyboard */,
A7C0EB761C2441C800110179 /* Info.plist */,
);
name = "DelayDemo-macOS";
path = "DelayDemo-OSX";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
A7C0EB691C2441C800110179 /* DelayDemo-OSX */ = {
A7C0EB691C2441C800110179 /* DelayDemo-macOS */ = {
isa = PBXNativeTarget;
buildConfigurationList = A7C0EB791C2441C800110179 /* Build configuration list for PBXNativeTarget "DelayDemo-OSX" */;
buildConfigurationList = A7C0EB791C2441C800110179 /* Build configuration list for PBXNativeTarget "DelayDemo-macOS" */;
buildPhases = (
A7C0EB661C2441C800110179 /* Sources */,
A7C0EB671C2441C800110179 /* Frameworks */,
......@@ -101,9 +102,9 @@
);
dependencies = (
);
name = "DelayDemo-OSX";
name = "DelayDemo-macOS";
productName = "DelayDemo-OSX";
productReference = A7C0EB6A1C2441C800110179 /* DelayDemo-OSX.app */;
productReference = A7C0EB6A1C2441C800110179 /* DelayDemo-macOS.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
......@@ -118,10 +119,11 @@
TargetAttributes = {
A7C0EB691C2441C800110179 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
};
};
buildConfigurationList = A7C0EB651C2441C800110179 /* Build configuration list for PBXProject "DelayDemo-OSX" */;
buildConfigurationList = A7C0EB651C2441C800110179 /* Build configuration list for PBXProject "DelayDemo-macOS" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
......@@ -134,7 +136,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
A7C0EB691C2441C800110179 /* DelayDemo-OSX */,
A7C0EB691C2441C800110179 /* DelayDemo-macOS */,
);
};
/* End PBXProject section */
......@@ -214,7 +216,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "";
LIBRARY_SEARCH_PATHS = "";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
......@@ -255,7 +257,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "";
LIBRARY_SEARCH_PATHS = "";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
......@@ -272,8 +274,10 @@
);
INFOPLIST_FILE = "DelayDemo-OSX/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.DelayDemo-OSX";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -288,15 +292,17 @@
);
INFOPLIST_FILE = "DelayDemo-OSX/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.DelayDemo-OSX";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
A7C0EB651C2441C800110179 /* Build configuration list for PBXProject "DelayDemo-OSX" */ = {
A7C0EB651C2441C800110179 /* Build configuration list for PBXProject "DelayDemo-macOS" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A7C0EB771C2441C800110179 /* Debug */,
......@@ -305,7 +311,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
A7C0EB791C2441C800110179 /* Build configuration list for PBXNativeTarget "DelayDemo-OSX" */ = {
A7C0EB791C2441C800110179 /* Build configuration list for PBXNativeTarget "DelayDemo-macOS" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A7C0EB7A1C2441C800110179 /* Debug */,
......
......@@ -7,14 +7,12 @@
objects = {
/* Begin PBXBuildFile section */
A7394BDD1CA435C70096FF28 /* Delay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7394BDC1CA435C70096FF28 /* Delay.framework */; };
A787D4771C24867500CDBF66 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A787D4761C24867500CDBF66 /* AppDelegate.swift */; };
A787D4791C24867500CDBF66 /* IOSViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A787D4781C24867500CDBF66 /* IOSViewController.swift */; };
A787D47C1C24867500CDBF66 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A787D47A1C24867500CDBF66 /* Main.storyboard */; };
A787D47E1C24867500CDBF66 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A787D47D1C24867500CDBF66 /* Assets.xcassets */; };
A787D4811C24867500CDBF66 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A787D47F1C24867500CDBF66 /* LaunchScreen.storyboard */; };
A787D48D1C24871A00CDBF66 /* Handle.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = A787D48C1C24871A00CDBF66 /* Handle.framework.dSYM */; };
A7D97E361CA4073D007C185B /* Handle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7D97E351CA4073D007C185B /* Handle.framework */; };
A7E2C25F1CA43ACB00CD92AE /* Delay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7394BDC1CA435C70096FF28 /* Delay.framework */; };
A7E2C2601CA43ACB00CD92AE /* Delay.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A7394BDC1CA435C70096FF28 /* Delay.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
......@@ -61,9 +59,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A7D97E361CA4073D007C185B /* Handle.framework in Frameworks */,
A7E2C25F1CA43ACB00CD92AE /* Delay.framework in Frameworks */,
A7394BDD1CA435C70096FF28 /* Delay.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -132,11 +128,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Aral Balkan";
TargetAttributes = {
A787D4721C24867500CDBF66 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
};
};
......@@ -233,8 +230,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";
......@@ -278,8 +277,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";
......@@ -298,6 +299,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;
};
......@@ -307,14 +309,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/../Carthage/Build/iOS",
"$(PROJECT_DIR)/$(CONFIGURATION_BUILD_DIR)",
);
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../Carthage/Build/iOS";
INFOPLIST_FILE = "DelayDemo-iOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.DelayDemo-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -322,14 +322,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/../Carthage/Build/iOS",
"$(PROJECT_DIR)/$(CONFIGURATION_BUILD_DIR)",
);
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../Carthage/Build/iOS";
INFOPLIST_FILE = "DelayDemo-iOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.DelayDemo-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
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 {
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:.
}
......
......@@ -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(Notification.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
if
let userInfo = notification.userInfo,
let keyboardFrameBegin = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue,
let keyboardFrameEnd = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
let 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(Notification.Name.UIKeyboardWillShow.rawValue, with: keyboardVisibilityWillChangeHandler)
keyboardWillHideHandler = keyboardWillHideHandler ?? handle(Notification.Name.UIKeyboardWillHide.rawValue, with: keyboardVisibilityWillChangeHandler)
}
override func viewWillDisappear(animated:Bool)
override func viewWillDisappear(_ animated:Bool)
{
super.viewWillDisappear(animated)
destroyNotificationHandler(&textDidChangeNotificationHandler)
......@@ -126,17 +126,17 @@ class IOSViewController: UIViewController, UITextFieldDelegate
// MARK: - Actions
//
@IBAction func threeSecondsButtonAction(sender: UIButton)
@IBAction func threeSecondsButtonAction(_ sender: UIButton)
{
threeSecondDelayLabel.text = "Waiting…"
delay(3)
_ = delay(3)
{
self.threeSecondDelayLabel.text = "Done!"
}
}
@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
......
......@@ -13,7 +13,7 @@ if hash carthage 2>/dev/null; then
echo "\nInstalling dependencies…\n"
# Install the dependencies for the demo apps.
carthage bootstrap
carthage bootstrap --platform iOS,Mac
# Done
printf "\n${successColour}Installation complete.${regularColour}\n\nTo start, type ./dev\n\n"
......
<
......@@ -2,19 +2,41 @@
Delay is an easy-to-use micro-library for delaying code execution in a cancellable manner. It uses Grand Central Dispatch and blocks.
**This is the master branch (Swift 2.2.1).** Also available: [Swift 2.3](https://source.ind.ie/project/delay/tree/swift-2.3) and [Swift 3](https://source.ind.ie/project/delay/tree/swift-3) branch
## Installation
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
Run the `./install` script to install the dependencies for the demo apps.
###1. Update your Cartfile
**Swift 3 (latest version)**
```
git "git@source.ind.ie:project/delay.git" ~> 3.0
```
For Swift 2.3, use the swift-2.3 branch: