Sitelet https://github.com/C4Labs/C4iOS/commit/19dbdcc064200ec9c7019c0900f2ae1c8b334c7b
Skip to content

Commit 19dbdcc

Browse files
Use new NSNotification.Name type
1 parent b8cb348 commit 19dbdcc

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎C4/Core/EventSource.swift‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ public protocol EventSource {
2525
/// Posts a new notification originating from the receiver.
2626
///
2727
/// - parameter event: The name of the event to post.
28-
func post(_ event: String)
28+
func post(_ event: NSNotification.Name)
2929

3030
/// Register an action to run when an event is triggered. Returns an observer handle you can use to cancel the action.
3131
///
3232
/// - parameter notificationName: The notification name to listen for
3333
/// - parameter executionBlock: A block of code to run when the receiver "hears" the specified notification name
3434
@discardableResult
35-
func on(event notificationName: String, run: @escaping () -> Void) -> AnyObject
35+
func on(event notificationName: NSNotification.Name, run: @escaping () -> Void) -> Any
3636

3737
/// Register an action to run when an event is triggered by the specified sender. Returns an observer handle you can use to cancel the action.
3838
///
3939
/// - parameter notificationName: The notification name to listen for
4040
/// - parameter sender: The object from which to listen for the notification
4141
/// - parameter executionBlock: A block of code to run when the receiver "hears" the specified notification name
4242
@discardableResult
43-
func on(event notificationName: String, from sender: AnyObject?, run executionBlock: @escaping () -> Void) -> AnyObject
43+
func on(event notificationName: NSNotification.Name, from sender: Any?, run executionBlock: @escaping () -> Void) -> Any
4444

4545
/// Cancel a previously registered action from an observer handle.
46-
func cancel(_ observer: AnyObject)
46+
func cancel(_ observer: Any)
4747
}
4848

4949
/// This extension allows any NSObject to post and listen for events in the same way as C4 objects.
@@ -58,8 +58,8 @@ extension NSObject: EventSource {
5858
/// ````
5959
///
6060
/// - parameter event: The notification name for the event
61-
public func post(_ event: String) {
62-
NotificationCenter.default.post(name: Notification.Name(rawValue: event), object: self)
61+
public func post(_ event: NSNotification.Name) {
62+
NotificationCenter.default.post(name: event, object: self)
6363
}
6464

6565
/// An action to run on receipt of a given event.
@@ -74,7 +74,7 @@ extension NSObject: EventSource {
7474
/// - parameter run: A block of code to run when the receiver "hears" the specified event name
7575
/// - returns: A token to use for cancelling the action.
7676
@discardableResult
77-
public func on(event notificationName: String, run executionBlock: @escaping () -> Void) -> AnyObject {
77+
public func on(event notificationName: NSNotification.Name, run executionBlock: @escaping () -> Void) -> Any {
7878
return on(event: notificationName, from: nil, run: executionBlock)
7979
}
8080

@@ -91,9 +91,9 @@ extension NSObject: EventSource {
9191
/// - parameter executionBlock: A block of code to run when the receiver "hears" the specified notification name
9292
/// - returns: A token to use for cancelling the action.
9393
@discardableResult
94-
public func on(event notificationName: String, from sender: AnyObject?, run executionBlock: @escaping () -> Void) -> AnyObject {
94+
public func on(event notificationName: NSNotification.Name, from sender: Any?, run executionBlock: @escaping () -> Void) -> Any {
9595
let nc = NotificationCenter.default
96-
let objectProtocol = nc.addObserver(forName: NSNotification.Name(rawValue: notificationName), object: sender, queue: OperationQueue.current, using: { _ in
96+
let objectProtocol = nc.addObserver(forName: notificationName, object: sender, queue: OperationQueue.current, using: { _ in
9797
executionBlock()
9898
})
9999
return objectProtocol
@@ -106,7 +106,7 @@ extension NSObject: EventSource {
106106
/// ````
107107
///
108108
/// - parameter token: A token returned from a call to `on(event:run:)` method
109-
public func cancel(_ token: AnyObject) {
109+
public func cancel(_ token: Any) {
110110
let nc = NotificationCenter.default
111111
nc.removeObserver(token)
112112
}

‎C4/UI/Camera.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Camera: View {
3838
var stillImageOutput: AVCaptureStillImageOutput?
3939
var captureSession: AVCaptureSession?
4040
var didCaptureAction: (() -> Void)?
41-
var orientationObserver: AnyObject?
41+
var orientationObserver: Any?
4242

4343
class CameraView: UIView {
4444
var previewLayer: PreviewLayer {
@@ -66,7 +66,7 @@ public class Camera: View {
6666
previewLayer.backgroundColor = clear.cgColor
6767
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
6868

69-
orientationObserver = on(event: NSNotification.Name.UIDeviceOrientationDidChange.rawValue) { [unowned self] in
69+
orientationObserver = on(event: NSNotification.Name.UIDeviceOrientationDidChange) { [unowned self] in
7070
self.updateOrientation()
7171
}
7272
}

‎C4/UI/Movie.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public class Movie: View {
167167
player = newPlayer
168168

169169
//runs an overrideable method for handling the end of the movie
170-
on(event: NSNotification.Name.AVPlayerItemDidPlayToEndTime.rawValue) {
170+
on(event: NSNotification.Name.AVPlayerItemDidPlayToEndTime) {
171171
self.handleReachedEnd()
172172
}
173173

0 commit comments

Comments
 (0)