Skip to content

Commit bf145ec

Browse files
committed
Fix warnings on Mac Catalyst
1 parent 74abf4a commit bf145ec

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

Demo/HudTests/HudTests.m

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,23 @@ - (void)testInitializers {
5555
UIView *nilView = nil;
5656
XCTAssertThrows([[MBProgressHUD alloc] initWithView:nilView]);
5757
XCTAssertNotNil([[MBProgressHUD alloc] initWithFrame:CGRectZero]);
58-
NSKeyedUnarchiver *dummyUnarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:[NSData data]];
58+
NSKeyedUnarchiver *dummyUnarchiver;
59+
#if !TARGET_OS_MACCATALYST
60+
if (@available(iOS 11.0, *)) {
61+
#endif
62+
dummyUnarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:[NSData data] error:nil];
63+
#if !TARGET_OS_MACCATALYST
64+
} else {
65+
dummyUnarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:[NSData data]];
66+
}
67+
#endif
5968
XCTAssertNotNil([[MBProgressHUD alloc] initWithCoder:dummyUnarchiver]);
6069
}
6170

6271
#pragma mark - Convenience
6372

6473
- (void)testNonAnimatedConvenienceHUDPresentation {
65-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
74+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
6675
UIView *rootView = rootViewController.view;
6776

6877
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:rootView animated:NO];
@@ -83,7 +92,7 @@ - (void)testNonAnimatedConvenienceHUDPresentation {
8392
}
8493

8594
- (void)testAnimatedConvenienceHUDPresentation {
86-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
95+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
8796
UIView *rootView = rootViewController.view;
8897

8998
self.hideExpectation = [self expectationWithDescription:@"The hudWasHidden: delegate should have been called."];
@@ -119,7 +128,7 @@ - (void)testAnimatedConvenienceHUDPresentation {
119128
}
120129

121130
- (void)testCompletionBlock {
122-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
131+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
123132
UIView *rootView = rootViewController.view;
124133

125134
self.hideExpectation = [self expectationWithDescription:@"The hudWasHidden: delegate should have been called."];
@@ -139,7 +148,7 @@ - (void)testCompletionBlock {
139148
#pragma mark - Modes
140149

141150
- (void)testRoundDeterminate {
142-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
151+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
143152
UIView *rootView = rootViewController.view;
144153

145154
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:rootView];
@@ -155,7 +164,7 @@ - (void)testRoundDeterminate {
155164
}
156165

157166
- (void)testRoundAnnularDeterminate {
158-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
167+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
159168
UIView *rootView = rootViewController.view;
160169

161170
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:rootView];
@@ -171,7 +180,7 @@ - (void)testRoundAnnularDeterminate {
171180
}
172181

173182
- (void)testDeterminateHorizontalBar {
174-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
183+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
175184
UIView *rootView = rootViewController.view;
176185

177186
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:rootView];
@@ -190,7 +199,7 @@ - (void)testDeterminateHorizontalBar {
190199
#pragma mark - Customization
191200

192201
- (void)testEffectViewOrderAfterSettingBlurStyle {
193-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
202+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
194203
UIView *rootView = rootViewController.view;
195204

196205
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:rootView];
@@ -209,7 +218,7 @@ - (void)testEffectViewOrderAfterSettingBlurStyle {
209218
#pragma mark - Delay
210219

211220
- (void)testDelayedHide {
212-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
221+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
213222
UIView *rootView = rootViewController.view;
214223

215224
self.hideExpectation = [self expectationWithDescription:@"The hudWasHidden: delegate should have been called."];
@@ -241,7 +250,7 @@ - (void)testDelayedHide {
241250

242251
- (void)testDelayedHideDoesNotRace {
243252
// https://github.com/jdg/MBProgressHUD/issues/503
244-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
253+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
245254
UIView *rootView = rootViewController.view;
246255

247256
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:rootView];
@@ -270,7 +279,7 @@ - (void)testDelayedHideDoesNotRace {
270279
#pragma mark - Ruse
271280

272281
- (void)testNonAnimatedHudReuse {
273-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
282+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
274283
UIView *rootView = rootViewController.view;
275284

276285
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:rootView];
@@ -289,7 +298,7 @@ - (void)testNonAnimatedHudReuse {
289298
}
290299

291300
- (void)testUnfinishedHidingAnimation {
292-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
301+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
293302
UIView *rootView = rootViewController.view;
294303

295304
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:rootView animated:NO];
@@ -314,7 +323,7 @@ - (void)testUnfinishedHidingAnimation {
314323
}
315324

316325
- (void)testAnimatedImmediateHudReuse {
317-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
326+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
318327
UIView *rootView = rootViewController.view;
319328

320329
XCTestExpectation *hideExpectation = [self expectationWithDescription:@"The hud should have been hidden."];
@@ -343,7 +352,7 @@ - (void)testAnimatedImmediateHudReuse {
343352
#pragma mark - Min show time
344353

345354
- (void)testMinShowTime {
346-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
355+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
347356
UIView *rootView = rootViewController.view;
348357

349358
self.hideExpectation = [self expectationWithDescription:@"The hudWasHidden: delegate should have been called."];
@@ -380,7 +389,7 @@ - (void)testMinShowTime {
380389
#pragma mark - Grace time
381390

382391
- (void)testGraceTime {
383-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
392+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
384393
UIView *rootView = rootViewController.view;
385394

386395
self.hideExpectation = [self expectationWithDescription:@"The hudWasHidden: delegate should have been called."];
@@ -421,7 +430,7 @@ - (void)testGraceTime {
421430
}
422431

423432
- (void)testHideBeforeGraceTimeElapsed {
424-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
433+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
425434
UIView *rootView = rootViewController.view;
426435

427436
self.hideExpectation = [self expectationWithDescription:@"The hudWasHidden: delegate should have been called."];
@@ -465,7 +474,7 @@ - (void)testHideBeforeGraceTimeElapsed {
465474
#pragma mark - Customization
466475

467476
- (void)testShape {
468-
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
477+
UIViewController *rootViewController = UIApplication.sharedApplication.windows.firstObject.rootViewController;
469478
UIView *rootView = rootViewController.view;
470479

471480
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:rootView];

0 commit comments

Comments
 (0)