From 97d82f6cca19dd6b9a1849f509e27698fdcc00d2 Mon Sep 17 00:00:00 2001 From: Christopher Luu Date: Wed, 27 Jan 2016 11:29:35 -0500 Subject: [PATCH] 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. --- CacheIsKingTests/CacheIsKingTests.swift | 4 ++-- Source/KingCache.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CacheIsKingTests/CacheIsKingTests.swift b/CacheIsKingTests/CacheIsKingTests.swift index 7ff3a95..89a6ba2 100644 --- a/CacheIsKingTests/CacheIsKingTests.swift +++ b/CacheIsKingTests/CacheIsKingTests.swift @@ -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) } diff --git a/Source/KingCache.swift b/Source/KingCache.swift index a655ac2..faf43c7 100644 --- a/Source/KingCache.swift +++ b/Source/KingCache.swift @@ -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)