Register and post notifications with an object

This commit is based on feedback that you should register UIApplication notification observers with the sharedApplication as the object.
This commit is contained in:
Christopher Luu 2016-01-27 11:29:35 -05:00
parent f93527d8cc
commit 97d82f6cca
2 changed files with 4 additions and 4 deletions

View file

@ -160,7 +160,7 @@ class CacheIsKingTests: XCTestCase {
XCTAssert(cache.count == 4)
NSNotificationCenter.defaultCenter().postNotificationName(UIApplicationDidReceiveMemoryWarningNotification, object: nil)
NSNotificationCenter.defaultCenter().postNotificationName(UIApplicationDidReceiveMemoryWarningNotification, object: UIApplication.sharedApplication())
XCTAssert(cache.count == 0)
@ -171,7 +171,7 @@ class CacheIsKingTests: XCTestCase {
XCTAssert(cache.count == 4)
NSNotificationCenter.defaultCenter().postNotificationName(UIApplicationDidEnterBackgroundNotification, object: nil)
NSNotificationCenter.defaultCenter().postNotificationName(UIApplicationDidEnterBackgroundNotification, object: UIApplication.sharedApplication())
XCTAssert(cache.count == 0)
}

View file

@ -33,13 +33,13 @@ public class KingCache {
var notificationObserver = NSNotificationCenter.defaultCenter()
.addObserverForName(UIApplicationDidReceiveMemoryWarningNotification,
object: nil,
object: UIApplication.sharedApplication(),
queue: nil,
usingBlock: removalBlock)
notificationObservers.append(notificationObserver)
notificationObserver = NSNotificationCenter.defaultCenter()
.addObserverForName(UIApplicationDidEnterBackgroundNotification,
object: nil,
object: UIApplication.sharedApplication(),
queue: nil,
usingBlock: removalBlock)
notificationObservers.append(notificationObserver)