Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification Static #92

Merged
merged 1 commit into from May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CriticalMass/ChatManager.swift
Expand Up @@ -24,7 +24,7 @@ class ChatManager {

init(requestManager: RequestManager) {
self.requestManager = requestManager
NotificationCenter.default.addObserver(self, selector: #selector(didReceiveMessages(notification:)), name: NSNotification.Name("chatMessagesReceived"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didReceiveMessages(notification:)), name: Notification.chatMessagesReceived, object: nil)
}

@objc private func didReceiveMessages(notification: Notification) {
Expand Down
4 changes: 2 additions & 2 deletions CriticalMass/LocationManager.swift
Expand Up @@ -40,7 +40,7 @@ class LocationManager: NSObject, CLLocationManagerDelegate, LocationProvider {
}
if let location = currentLocation {
didSetInitialLocation = true
NotificationCenter.default.post(name: NSNotification.Name("initialGpsDataReceived"), object: location)
NotificationCenter.default.post(name: Notification.initialGpsDataReceived, object: location)
}
}
get {
Expand Down Expand Up @@ -95,6 +95,6 @@ class LocationManager: NSObject, CLLocationManagerDelegate, LocationProvider {
}

func locationManager(_: CLLocationManager, didChangeAuthorization _: CLAuthorizationStatus) {
NotificationCenter.default.post(name: NSNotification.Name("gpsStateChanged"), object: type(of: self).accessPermission)
NotificationCenter.default.post(name: Notification.gpsStateChanged, object: type(of: self).accessPermission)
}
}
6 changes: 3 additions & 3 deletions CriticalMass/MapViewController.swift
Expand Up @@ -106,9 +106,9 @@ class MapViewController: UIViewController {
}

private func configureNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(positionsDidChange(notification:)), name: NSNotification.Name("positionOthersChanged"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didReceiveInitialLocation(notification:)), name: NSNotification.Name("initialGpsDataReceived"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(updateGPSDisabledOverlayVisibility), name: NSNotification.Name("gpsStateChanged"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(positionsDidChange(notification:)), name: Notification.positionOthersChanged, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didReceiveInitialLocation(notification:)), name: Notification.initialGpsDataReceived, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(updateGPSDisabledOverlayVisibility), name: Notification.gpsStateChanged, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: Notification.themeDidChange, object: nil)
}

Expand Down
4 changes: 2 additions & 2 deletions CriticalMass/MemoryDataStore.swift
Expand Up @@ -11,10 +11,10 @@ class MemoryDataStore: DataStore {
private var lastKnownResponse: ApiResponse? {
didSet {
if oldValue?.locations != lastKnownResponse?.locations {
NotificationCenter.default.post(name: NSNotification.Name("positionOthersChanged"), object: lastKnownResponse)
NotificationCenter.default.post(name: Notification.positionOthersChanged, object: lastKnownResponse)
}
if oldValue?.chatMessages != lastKnownResponse?.chatMessages {
NotificationCenter.default.post(name: NSNotification.Name("chatMessagesReceived"), object: lastKnownResponse)
NotificationCenter.default.post(name: Notification.chatMessagesReceived, object: lastKnownResponse)
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion CriticalMass/Notification+Static.swift
@@ -1,5 +1,5 @@
//
// NSNotification+Static.swift
// Notification+Static.swift
// CriticalMaps
//
// Created by Malte Bünz on 19.04.19.
Expand All @@ -10,4 +10,8 @@ import Foundation

extension Notification {
static let themeDidChange = Notification.Name(rawValue: "themeDidChange")
static let initialGpsDataReceived = Notification.Name(rawValue: "initialGpsDataReceived")
static let gpsStateChanged = Notification.Name(rawValue: "gpsStateChanged")
static let positionOthersChanged = Notification.Name(rawValue: "positionOthersChanged")
static let chatMessagesReceived = Notification.Name(rawValue: "chatMessagesReceived")
}
2 changes: 1 addition & 1 deletion CriticalMass/Preferences.swift
Expand Up @@ -14,7 +14,7 @@ class Preferences {
}
set {
UserDefaults.standard.set(newValue, forKey: #function)
NotificationCenter.default.post(name: NSNotification.Name("gpsStateChanged"), object: newValue)
NotificationCenter.default.post(name: Notification.gpsStateChanged, object: newValue)
}
}

Expand Down
8 changes: 4 additions & 4 deletions CriticalMassTests/MemoryDataStoreTests.swift
Expand Up @@ -12,7 +12,7 @@ class MemoryDataStoreTests: XCTestCase {
func testNotificationAfterStoringLocations() {
let store = MemoryDataStore()
let expectedObject = ApiResponse(locations: ["a": Location(longitude: 100, latitude: 100, timestamp: 100, name: "hello", color: "world")], chatMessages: [:])
let notificationName = NSNotification.Name("positionOthersChanged")
let notificationName = Notification.positionOthersChanged
let exp = expectation(forNotification: notificationName, object: nil) { (notification) -> Bool in
notification.object as AnyObject as! ApiResponse == expectedObject
}
Expand All @@ -24,7 +24,7 @@ class MemoryDataStoreTests: XCTestCase {
func testNotificationAfterStoringChatMessage() {
let store = MemoryDataStore()
let expectedObject = ApiResponse(locations: [:], chatMessages: ["b": ChatMessage(message: "Hello", timestamp: 1000)])
let notificationName = NSNotification.Name("positionOthersChanged")
let notificationName = Notification.positionOthersChanged
let exp = expectation(forNotification: notificationName, object: nil) { (notification) -> Bool in
notification.object as AnyObject as! ApiResponse == expectedObject
}
Expand All @@ -36,7 +36,7 @@ class MemoryDataStoreTests: XCTestCase {
func testNoNoDoublicatedNotificationAfterStoringOldLocations() {
let store = MemoryDataStore()
let expectedObject = ApiResponse(locations: ["a": Location(longitude: 100, latitude: 100, timestamp: 100, name: "hello", color: "world")], chatMessages: [:])
let notificationName = NSNotification.Name("positionOthersChanged")
let notificationName = Notification.positionOthersChanged
var notificationCount = 0
let exp = expectation(forNotification: notificationName, object: nil) { (notification) -> Bool in
notificationCount += 1
Expand All @@ -54,7 +54,7 @@ class MemoryDataStoreTests: XCTestCase {
let store = MemoryDataStore()
let expectedObject = ApiResponse(locations: [:], chatMessages: ["b": ChatMessage(message: "Hello", timestamp: 1000)])
var notificationCount = 0
let notificationName = NSNotification.Name("positionOthersChanged")
let notificationName = Notification.positionOthersChanged
let exp = expectation(forNotification: notificationName, object: nil) { (notification) -> Bool in
notificationCount += 1
return notification.object as AnyObject as! ApiResponse == expectedObject
Expand Down