Commit 1358fd34 authored by Aral Balkan's avatar Aral Balkan
Browse files

Update to Swift 3.

parent ad0951a2
......@@ -337,7 +337,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
VALID_ARCHS = "arm64 armv7 armv7s i386 x86_64";
};
name = Debug;
......@@ -360,7 +360,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
VALID_ARCHS = "arm64 armv7 armv7s i386 x86_64";
};
name = Release;
......
......@@ -11,13 +11,13 @@
import Foundation
let 📡:NSNotificationCenter = NSNotificationCenter.defaultCenter()
let 📡:NotificationCenter = NotificationCenter.default()
public typealias NotificationBlock = (NSNotification!) -> Void
public typealias NotificationBlock = (Notification!) -> Void
// Utility method: destroy a notification handler
public func destroyNotificationHandler(inout handler:NotificationHandler?)
public func destroyNotificationHandler(_ handler:inout NotificationHandler?)
{
handler?.remove()
handler = nil
......@@ -38,7 +38,7 @@ public class NotificationHandler:NSObject
self.handler = handler
}
public func handlerProxy(notification:NSNotification!)
public func handlerProxy(_ notification:Notification!)
{
handler(notification)
}
......@@ -69,7 +69,7 @@ public class NotificationHandler:NSObject
//
public func handle(notificationName:String, with block:NotificationBlock) -> NotificationHandler
public func handle(_ notificationName:String, with block:NotificationBlock) -> NotificationHandler
{
//
// Instead of using the block-based methods of NSNotificationCenter, create an observer
......@@ -81,7 +81,7 @@ public func handle(notificationName:String, with block:NotificationBlock) -> Not
}
public func handle(notificationName:String, from object:AnyObject?, with block:NotificationBlock) -> NotificationHandler
public func handle(_ notificationName:String, from object:AnyObject?, with block:NotificationBlock) -> NotificationHandler
{
let observer = NotificationHandler(handler: block)
📡.addObserver(observer, selector: #selector(observer.handlerProxy(_:)), name: notificationName, object: object)
......@@ -94,20 +94,20 @@ public func handle(notificationName:String, from object:AnyObject?, with block:N
//
public func post(notificationName:String, from object:AnyObject?, with userInfo:[NSObject : AnyObject]?)
public func post(_ notificationName:String, from object:AnyObject?, with userInfo:[NSObject : AnyObject]?)
{
// println("About to post: \(notificationName) notification from \(object) with userInfo: \(userInfo)")
📡.post(notificationName, from: object, with: userInfo)
📡.post(name: NSNotification.Name(rawValue: notificationName), object: object, userInfo: userInfo)
}
public func post(notificationName:String, from object:AnyObject?)
public func post(_ notificationName:String, from object:AnyObject?)
{
📡.post(notificationName, from: object, with: /* userInfo as */ nil)
📡.post(name: NSNotification.Name(rawValue: notificationName), object: object, userInfo: /* userInfo as */ nil)
}
public func post(notificationName:String)
public func post(_ notificationName:String)
{
📡.post(notificationName)
}
......@@ -124,13 +124,13 @@ public func post(notificationName:String)
// MARK: - Handling notifications
//
public func handle(notificationName:String, with selector:Selector, on observer:AnyObject)
public func handle(_ notificationName:String, with selector:Selector, on observer:AnyObject)
{
📡.addObserver(observer, selector: selector, name: notificationName, object: nil)
}
public func handle(notificationName:String, from object:AnyObject?, with selector:Selector, on observer:AnyObject)
public func handle(_ notificationName:String, from object:AnyObject?, with selector:Selector, on observer:AnyObject)
{
📡.addObserver(observer, selector: selector, name: notificationName, object: object)
}
......@@ -140,13 +140,13 @@ public func handle(notificationName:String, from object:AnyObject?, with selecto
// MARK: - Removing notification handlers.
//
public func remove(observer observer:AnyObject, forNotificationNamed name:String?)
public func remove(observer:AnyObject, forNotificationNamed name:String?)
{
📡.removeObserver(observer, name: name, object: nil)
📡.removeObserver(observer, name: name.map { NSNotification.Name(rawValue: $0) }, object: nil)
}
public func remove(observer observer:AnyObject, forNotificationNamed name:String?, from object:AnyObject?)
public func remove(observer:AnyObject, forNotificationNamed name:String?, from object:AnyObject?)
{
📡.removeObserver(observer, name: name, object: object)
📡.removeObserver(observer, name: name.map { NSNotification.Name(rawValue: $0) }, object: object)
}
......@@ -22,19 +22,19 @@
// MARK: - Extension
//
extension NSNotificationCenter
extension NotificationCenter
{
//
// MARK: - Adding observers
//
public func handle(notificationName:String, with selector:Selector, on observer:AnyObject)
public func handle(_ notificationName:String, with selector:Selector, on observer:AnyObject)
{
self.addObserver(observer, selector: selector, name: notificationName, object: nil)
}
public func handle(notificationName:String, from object:AnyObject?, with selector:Selector, on observer:AnyObject)
public func handle(_ notificationName:String, from object:AnyObject?, with selector:Selector, on observer:AnyObject)
{
self.addObserver(observer, selector: selector, name: notificationName, object: object)
}
......@@ -45,15 +45,15 @@ extension NSNotificationCenter
//
public func remove(observer observer:AnyObject, forNotificationNamed name:String?)
public func remove(observer:AnyObject, forNotificationNamed name:String?)
{
self.removeObserver(observer, name: name, object: nil)
self.removeObserver(observer, name: name.map { NSNotification.Name(rawValue: $0) }, object: nil)
}
public func remove(observer observer:AnyObject, forNotificationNamed name:String?, from object:AnyObject?)
public func remove(observer:AnyObject, forNotificationNamed name:String?, from object:AnyObject?)
{
self.removeObserver(observer, name: name, object: object)
self.removeObserver(observer, name: name.map { NSNotification.Name(rawValue: $0) }, object: object)
}
......@@ -62,29 +62,29 @@ extension NSNotificationCenter
//
public func post(notificationName:String, from object:AnyObject?, with userInfo:[NSObject : AnyObject]?)
public func post(_ notificationName:String, from object:AnyObject?, with userInfo:[NSObject : AnyObject]?)
{
// Note: notifications are dispatched on the main thread. This is most likely what you’re expecting anyway.
// (And if not, I’m sure you’re wizard enough to send me a pull request.) ;)
dispatch_async(dispatch_get_main_queue())
DispatchQueue.main.async
{
self.postNotificationName(notificationName, object: object, userInfo: userInfo)
self.post(name: Notification.Name(rawValue: notificationName), object: object, userInfo: userInfo)
}
}
public func post(notificationName:String, from object:AnyObject?)
public func post(_ notificationName:String, from object:AnyObject?)
{
self.post(notificationName, from: object, with: /* userInfo as */ nil)
}
public func post(notificationName:String)
public func post(_ notificationName:String)
{
#if os(OSX)
self.post(notificationName, from: NSApplication.sharedApplication(), with: /* userInfo as */ nil)
#elseif os(iOS)
self.post(notificationName, from: UIApplication.sharedApplication(), with: /* userInfo as */ nil)
self.post(notificationName, from: UIApplication.shared(), with: /* userInfo as */ nil)
#endif
}
......@@ -96,4 +96,4 @@ extension NSNotificationCenter
// {
// self.postNotification(notification)
// }
}
\ No newline at end of file
}
......@@ -274,7 +274,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.HandleDemo-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
......@@ -286,7 +286,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ind.ie.HandleDemo-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:.
}
......
......@@ -23,7 +23,7 @@ class ViewController: UIViewController
{
super.viewDidLoad()
orientationWillChangeHandler = orientationWillChangeHandler ?? handle(UIApplicationWillChangeStatusBarOrientationNotification)
orientationWillChangeHandler = orientationWillChangeHandler ?? handle(NSNotification.Name.UIApplicationWillChangeStatusBarOrientation.rawValue)
{
/* with */ notification in
......@@ -40,7 +40,7 @@ class ViewController: UIViewController
// Dispose of any resources that can be recreated.
}
@IBAction func stopListeningForOrientationChanges(sender: UIButton)
@IBAction func stopListeningForOrientationChanges(_ sender: UIButton)
{
destroyNotificationHandler(&orientationWillChangeHandler)
orientationLabel.text = "No longer handling notifications."
......@@ -48,7 +48,7 @@ class ViewController: UIViewController
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
{
return .All
return .all
}
}
......@@ -2,18 +2,18 @@
Handle is an easy-to-use, expressive Swift micro-library for handling notifications.
**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.
## Installation
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
To include the Swift 2.3 version, make sure you specify the swift-2.3 branch in your Cartfile:
To include the Swift 3 version, make sure you specify the swift-3 branch in your Cartfile:
```
git "git@source.ind.ie:project/handle.git" "swift-2.3"
git "git@source.ind.ie:project/handle.git" "swift-3"
```
The Handle demonstration apps do not have any dependencies, just open up the Delay.xcworkspace in Xcode and build and run the iOS and OS X demos.
......
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