Ind.ie is now Small Technology Foundation.
Commit d6ad24dd authored by Aral Balkan's avatar Aral Balkan

Update to Swift 3

API change: Timer is not IndieTimer to resolve ambiguity with
Foundation.Timer (Timer.Timer did not fix this in Beta 2.)
parent f4731d64
......@@ -245,7 +245,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -263,7 +263,7 @@
PRODUCT_BUNDLE_IDENTIFIER = ind.ie.Timer;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......
......@@ -25,11 +25,11 @@
import Foundation
public class Timer
public class IndieTimer
{
public typealias TickHandler = (Timer)->Void
public typealias TickHandler = (IndieTimer)->Void
var timer:NSTimer?
var timer:Foundation.Timer?
let tickInterval:Double
let tickHandler:TickHandler
......@@ -39,14 +39,14 @@ public class Timer
self.tickHandler = tickHandler
}
public func start(repeats repeats: Bool = true) -> Timer
public func start(repeats: Bool = true) -> IndieTimer
{
timer = NSTimer.scheduledTimerWithTimeInterval(tickInterval, target: self, selector: #selector(self.tick), userInfo: nil, repeats: repeats)
timer = Foundation.Timer.scheduledTimer(timeInterval: tickInterval, target: self, selector: #selector(self.tick), userInfo: nil, repeats: repeats)
return self
}
public func stop() -> Timer
public func stop() -> IndieTimer
{
timer?.invalidate()
......
......@@ -12,7 +12,6 @@
A727AA2B1C9EFD8100F44ED3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A727AA291C9EFD8100F44ED3 /* Main.storyboard */; };
A727AA2D1C9EFD8100F44ED3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A727AA2C1C9EFD8100F44ED3 /* Assets.xcassets */; };
A727AA301C9EFD8100F44ED3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A727AA2E1C9EFD8100F44ED3 /* LaunchScreen.storyboard */; };
A72BFA0A1CA43209002BAD35 /* Timer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A72BFA091CA43209002BAD35 /* Timer.framework */; };
A7394BDE1CA4377A0096FF28 /* Timer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A72BFA091CA43209002BAD35 /* Timer.framework */; };
A7394BDF1CA4377A0096FF28 /* Timer.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A72BFA091CA43209002BAD35 /* Timer.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
......@@ -48,7 +47,6 @@
buildActionMask = 2147483647;
files = (
A7394BDE1CA4377A0096FF28 /* Timer.framework in Frameworks */,
A72BFA0A1CA43209002BAD35 /* Timer.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -113,7 +111,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Aral Balkan";
TargetAttributes = {
A727AA211C9EFD8100F44ED3 = {
......@@ -278,7 +276,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.TimerDemo-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -294,7 +292,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.TimerDemo-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
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:.
}
......
......@@ -11,8 +11,8 @@ import Timer
class ViewController: UIViewController
{
var timer:Timer?
var elapsedTime:NSTimeInterval = 0.0 // in seconds.
var timer:IndieTimer?
var elapsedTime:TimeInterval = 0.0 // in seconds.
@IBOutlet weak var displayLabel: UILabel!
......@@ -28,17 +28,17 @@ class ViewController: UIViewController
func reset()
{
timer?.stop()
_ = timer?.stop()
self.elapsedTime = 0.0
updateDisplay()
}
func updateDisplay()
{
let formatter = NSDateComponentsFormatter()
formatter.unitsStyle = .SpellOut
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .spellOut
if let formattedTime = formatter.stringFromTimeInterval(self.elapsedTime)
if let formattedTime = formatter.string(from: self.elapsedTime)
{
self.displayLabel.text = formattedTime
}
......@@ -46,24 +46,24 @@ class ViewController: UIViewController
// MARK: - Actions
@IBAction func resetButtonPressed(sender: UIButton)
@IBAction func resetButtonPressed(_ sender: UIButton)
{
reset()
}
@IBAction func stopButtonPressed(sender: UIButton)
@IBAction func stopButtonPressed(_ sender: UIButton)
{
timer?.stop()
_ = timer?.stop()
}
@IBAction func startButtonPressed(sender: UIButton)
@IBAction func startButtonPressed(_ sender: UIButton)
{
timer?.stop()
_ = timer?.stop()
timer = nil
timer =
(
Timer(tickInterval: 1.0)
IndieTimer(tickInterval: 1.0)
{
/* with */ timer in
......
# Timer
A simple wrapper for NSTimer in Swift that lets you create timers using Swifty syntax and closures.
A simple wrapper for Foundation.Timer in Swift that lets you create timers using Swifty syntax and closures.
**This is the Swift 2.3 branch.**
**This is the Swift 3 branch.**
See `master` branch for the current release (Swift 2.2.1) version and the `swift-3` branch for the Swift 3.x version.
See `master` branch for the current release (Swift 2.2.1) version and the `swift-2.3` branch for the Swift 2.3 version.
**API change:** Since Timer is now ambigious with Foundation.Timer in Swift 3, I’ve renamed the class to IndieTimer. This will break existing code. Unfortunately, in Beta 2 at least, Timer.Timer does not resolve the ambiguity.
## Installation
......@@ -12,10 +14,10 @@ See `master` branch for the current release (Swift 2.2.1) version and the `swift
Run the `./install` script to install the dependencies for the demo app.
To include the Swift 2.3 version in your own projects, please make sure you specify the swift-2.3 branch in your Cartfile:
To include the Swift 3 version in your own projects, please make sure you specify the swift-3 branch in your Cartfile:
```
git "git@source.ind.ie:project/timer.git" "swift-2.3"
git "git@source.ind.ie:project/timer.git" "swift-3"
```
## Getting started
......@@ -25,7 +27,7 @@ Run the `./dev` script and play with the iOS demo app.
## Usage
```swift
let myTimer = (Timer(tickInterval: 1.0)
let myTimer = (IndieTimer(tickInterval: 1.0)
{
/* with */ timer in
......@@ -34,7 +36,7 @@ let myTimer = (Timer(tickInterval: 1.0)
// Stopping the timer so it doesn’t repeat.
// You can also call .start(repeats: false)
// to achieve the same effect.
timer.stop()
_ = timer.stop()
}).start()
```
......
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