File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -1292,7 +1292,8 @@ extension KingfisherWrapper where Base: UIApplication {
12921292 public static var shared : UIApplication ? {
12931293 let selector = NSSelectorFromString ( " sharedApplication " )
12941294 guard Base . responds ( to: selector) else { return nil }
1295- return Base . perform ( selector) . takeUnretainedValue ( ) as? UIApplication
1295+ guard let unmanaged = Base . perform ( selector) else { return nil }
1296+ return unmanaged. takeUnretainedValue ( ) as? UIApplication
12961297 }
12971298}
12981299#endif
Original file line number Diff line number Diff line change @@ -895,7 +895,15 @@ class ImageCacheTests: XCTestCase {
895895 let result = try XCTUnwrap ( fileURL)
896896 XCTAssertTrue ( result. absoluteString. hasSuffix ( " .myExt " ) )
897897 }
898-
898+
899+ #if !os(macOS) && !os(watchOS)
900+ func testKingfisherWrapperUIApplicationSharedReturnsNilInUnitTest( ) {
901+ // UIApplication.shared is not available in some Unit Tests contexts.
902+ // This tests that accessing it via KingfisherWrapper does not cause a crash.
903+ XCTAssertNil ( KingfisherWrapper< UIApplication> . shared)
904+ }
905+ #endif
906+
899907 // MARK: - Helper
900908 private func storeMultipleImages( _ completionHandler: @escaping ( ) -> Void ) {
901909 let group = DispatchGroup ( )
You can’t perform that action at this time.
0 commit comments