@@ -43,7 +43,10 @@ class ImageCacheTests: XCTestCase {
43
43
override func tearDown( ) {
44
44
clearCaches ( [ cache] )
45
45
cache = nil
46
- observer = nil
46
+ if let o = observer {
47
+ NotificationCenter . default. removeObserver ( o)
48
+ observer = nil
49
+ }
47
50
48
51
super. tearDown ( )
49
52
}
@@ -351,28 +354,27 @@ class ImageCacheTests: XCTestCase {
351
354
352
355
cache. diskStorage. config. expiration = . seconds( 0.01 )
353
356
357
+ let selfCache = self . cache
354
358
cache. store ( testImage, original: testImageData, forKey: key, toDisk: true ) { _ in
355
359
self . observer = NotificationCenter . default. addObserver (
356
360
forName: . KingfisherDidCleanDiskCache,
357
361
object: self . cache,
358
- queue: . main) {
359
- noti in
360
- let receivedCache = noti. object as? ImageCache
361
- XCTAssertNotNil ( receivedCache)
362
- XCTAssertTrue ( receivedCache === self . cache)
363
-
364
- guard let hashes = noti. userInfo ? [ KingfisherDiskCacheCleanedHashKey] as? [ String ] else {
365
- XCTFail ( " Notification should contains Strings in key 'KingfisherDiskCacheCleanedHashKey' " )
366
- exp. fulfill ( )
367
- return
368
- }
369
-
370
- XCTAssertEqual ( hashes. count, 1 )
371
- XCTAssertEqual ( hashes. first!, self . cache. hash ( forKey: key) )
372
- guard let o = self . observer else { return }
373
- NotificationCenter . default. removeObserver ( o)
362
+ queue: . main
363
+ ) { noti in
364
+ let receivedCache = noti. object as? ImageCache
365
+ XCTAssertNotNil ( receivedCache)
366
+ XCTAssertTrue ( receivedCache === selfCache)
367
+
368
+ guard let hashes = noti. userInfo ? [ KingfisherDiskCacheCleanedHashKey] as? [ String ] else {
369
+ XCTFail ( " Notification should contains Strings in key 'KingfisherDiskCacheCleanedHashKey' " )
374
370
exp. fulfill ( )
371
+ return
375
372
}
373
+
374
+ XCTAssertEqual ( hashes. count, 1 )
375
+ XCTAssertEqual ( hashes. first!, selfCache!. hash ( forKey: key) )
376
+ exp. fulfill ( )
377
+ }
376
378
377
379
delay ( 1 ) {
378
380
self . cache. cleanExpiredDiskCache ( )
0 commit comments