From d0fe14d00a861a6b3a198f929d3587adbe42894e Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Sun, 7 Mar 2021 16:55:05 +0100 Subject: [PATCH] [ios] Nullable warning fixes Signed-off-by: Alexander Borsuk --- .../BookmarksList/BookmarksListBuilder.swift | 2 +- .../Catalog/CatalogWebViewController.swift | 2 +- .../Maps/Classes/CarPlay/CarPlayService.swift | 6 +++-- .../AlertController/MWMAlertViewController.h | 2 +- .../MWMNavigationDashboardManager.h | 12 ++++----- iphone/Maps/Classes/MapViewController.h | 24 ++++++++--------- .../DeepLinkSubscriptionStrategy.swift | 3 ++- .../Core/Notifications/MWMPushNotifications.h | 26 +++++++++---------- .../Maps/UI/AvailableArea/VisibleArea.swift | 2 +- .../GuidesGallery/GuidesGalleryBuilder.swift | 2 +- .../Maps/UI/PlacePage/PlacePageBuilder.swift | 2 +- .../UI/PlacePage/PlacePageInteractor.swift | 5 ++-- .../PlacePage/PlacePageViewController.swift | 2 +- .../SearchCategoriesViewController.swift | 2 +- .../UI/Welcome/WhatsNew/WhatsNewBuilder.swift | 5 ++-- 15 files changed, 51 insertions(+), 46 deletions(-) diff --git a/iphone/Maps/Bookmarks/BookmarksList/BookmarksListBuilder.swift b/iphone/Maps/Bookmarks/BookmarksList/BookmarksListBuilder.swift index 38117421da..14208abed4 100644 --- a/iphone/Maps/Bookmarks/BookmarksList/BookmarksListBuilder.swift +++ b/iphone/Maps/Bookmarks/BookmarksList/BookmarksListBuilder.swift @@ -3,7 +3,7 @@ final class BookmarksListBuilder { bookmarksCoordinator: BookmarksCoordinator?, delegate: BookmarksListDelegate? = nil) -> BookmarksListViewController { let viewController = BookmarksListViewController() - let router = BookmarksListRouter(MapViewController.shared(), bookmarksCoordinator: bookmarksCoordinator) + let router = BookmarksListRouter(MapViewController.shared()!, bookmarksCoordinator: bookmarksCoordinator) let interactor = BookmarksListInteractor(markGroupId: markGroupId) let presenter = BookmarksListPresenter(view: viewController, router: router, diff --git a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift index 0815d54ee5..1b069a3d56 100644 --- a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift @@ -343,7 +343,7 @@ final class CatalogWebViewController: WebViewController { } else { if BookmarksManager.shared().getCatalogDownloadsCount() == 0 { logToPushWoosh(categoryInfo) - MapViewController.shared().showBookmarksLoadedAlert(categoryId) + MapViewController.shared()?.showBookmarksLoadedAlert(categoryId) } } self?.updateProgress() diff --git a/iphone/Maps/Classes/CarPlay/CarPlayService.swift b/iphone/Maps/Classes/CarPlay/CarPlayService.swift index ce145f4ce9..e998d0efce 100644 --- a/iphone/Maps/Classes/CarPlay/CarPlayService.swift +++ b/iphone/Maps/Classes/CarPlay/CarPlayService.swift @@ -60,8 +60,10 @@ final class CarPlayService: NSObject { if let carplayVC = carplayVC { carplayVC.removeMapView() } - MapViewController.shared()?.disableCarPlayRepresentation() - MapViewController.shared()?.remove(self) + if let mvc = MapViewController.shared() { + mvc.disableCarPlayRepresentation() + mvc.remove(self) + } router?.removeListener(self) router?.unsubscribeFromEvents() router?.setupInitialSpeedCameraMode() diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h index 04bda952ee..932b465a9d 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h @@ -14,7 +14,7 @@ - (void)presentPoint2PointAlertWithOkBlock:(nonnull MWMVoidBlock)okBlock needToRebuild:(BOOL)needToRebuild; - (void)presentRoutingDisclaimerAlertWithOkBlock:(nonnull nonnull MWMVoidBlock)block; - (void)presentDisabledLocationAlert; -- (void)presentLocationAlertWithCancelBlock:(MWMVoidBlock)cancelBlock; +- (void)presentLocationAlertWithCancelBlock:(MWMVoidBlock _Nonnull )cancelBlock; - (void)presentLocationServiceNotSupportedAlert; - (void)presentLocationNotFoundAlertWithOkBlock:(nonnull MWMVoidBlock)okBlock; - (void)presentNoConnectionAlert; diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.h b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.h index cb1ec5f33e..c583a38a55 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.h +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.h @@ -13,19 +13,19 @@ typedef NS_ENUM(NSUInteger, MWMNavigationDashboardState) { @interface MWMNavigationDashboardManager : NSObject + (nonnull MWMNavigationDashboardManager *)sharedManager; -+ (void)addObserver:(id)observer; -+ (void)removeObserver:(id)observer; ++ (void)addObserver:(id_Nonnull)observer; ++ (void)removeObserver:(id_Nonnull)observer; @property(nonatomic, readonly) MWMNavigationDashboardState state; -@property(nonatomic, readonly) MWMTaxiPreviewDataSource *taxiDataSource; +@property(nonatomic, readonly) MWMTaxiPreviewDataSource * _Nonnull taxiDataSource; -- (instancetype)init __attribute__((unavailable("init is not available"))); -- (instancetype)initWithParentView:(UIView *)view; +- (instancetype _Nonnull)init __attribute__((unavailable("init is not available"))); +- (instancetype _Nonnull)initWithParentView:(UIView *_Nonnull)view; - (void)setRouteBuilderProgress:(CGFloat)progress; - (void)onRoutePrepare; - (void)onRoutePlanning; -- (void)onRouteError:(NSString *)error; +- (void)onRouteError:(NSString *_Nonnull)error; - (void)onRouteReady:(BOOL)hasWarnings; - (void)onRouteStart; - (void)onRouteStop; diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index ce6621a60f..96ba504671 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -13,9 +13,9 @@ @interface MapViewController : MWMViewController -+ (MapViewController *)sharedController; -- (void)addListener:(id)listener; -- (void)removeListener:(id)listener; ++ (MapViewController *_Nullable)sharedController; +- (void)addListener:(id_Nonnull)listener; +- (void)removeListener:(id_Nonnull)listener; // called when app is terminated by system - (void)onTerminate; @@ -23,18 +23,18 @@ - (void)updateStatusBarStyle; -- (void)performAction:(NSString *)action; +- (void)performAction:(NSString *_Nonnull)action; - (void)openMapsDownloader:(MWMMapDownloaderMode)mode; - (void)openEditor; - (void)openBookmarkEditor; -- (void)openFullPlaceDescriptionWithHtml:(NSString *)htmlString; +- (void)openFullPlaceDescriptionWithHtml:(NSString *_Nonnull)htmlString; - (void)showUGCAuth; - (void)showBookmarksLoadedAlert:(UInt64)categoryId; - (void)openCatalogAnimated:(BOOL)animated utm:(MWMUTM)utm; -- (void)openCatalogDeeplink:(NSURL *)deeplinkUrl animated:(BOOL)animated utm:(MWMUTM)utm; -- (void)openCatalogAbsoluteUrl:(NSURL *)url animated:(BOOL)animated utm:(MWMUTM)utm; -- (void)searchText:(NSString *)text; +- (void)openCatalogDeeplink:(NSURL *_Nonnull)deeplinkUrl animated:(BOOL)animated utm:(MWMUTM)utm; +- (void)openCatalogAbsoluteUrl:(NSURL *_Nullable)url animated:(BOOL)animated utm:(MWMUTM)utm; +- (void)searchText:(NSString *_Nonnull)text; - (void)openDrivingOptions; - (void)showRemoveAds; @@ -48,10 +48,10 @@ - (void)dismissPlacePage; -@property(nonatomic, readonly) MWMMapViewControlsManager * controlsManager; -@property(nonatomic) MWMWelcomePageController * welcomePageController; -@property(nonatomic, readonly) MWMMapDownloadDialog * downloadDialog; -@property(nonatomic, readonly) BookmarksCoordinator * bookmarksCoordinator; +@property(nonatomic, readonly) MWMMapViewControlsManager * _Nonnull controlsManager; +@property(nonatomic) MWMWelcomePageController * _Nullable welcomePageController; +@property(nonatomic, readonly) MWMMapDownloadDialog * _Nonnull downloadDialog; +@property(nonatomic, readonly) BookmarksCoordinator * _Nonnull bookmarksCoordinator; @property(nonatomic) MWMMyPositionMode currentPositionMode; @property(strong, nonatomic) IBOutlet EAGLView * _Nonnull mapView; diff --git a/iphone/Maps/Core/DeepLink/Strategies/DeepLinkSubscriptionStrategy.swift b/iphone/Maps/Core/DeepLink/Strategies/DeepLinkSubscriptionStrategy.swift index 48da63bf40..7f06d5cf61 100644 --- a/iphone/Maps/Core/DeepLink/Strategies/DeepLinkSubscriptionStrategy.swift +++ b/iphone/Maps/Core/DeepLink/Strategies/DeepLinkSubscriptionStrategy.swift @@ -9,7 +9,8 @@ class DeepLinkSubscriptionStrategy: IDeepLinkHandlerStrategy { func execute() { guard let mapViewController = MapViewController.shared() else { - return; + LOG(.error, "DeepLinkSubscriptionStrategy: mapViewController is nil"); + return } guard let type: SubscriptionGroupType = SubscriptionGroupType(serverId: data.groups) else { LOG(.error, "Groups is wrong: \(deeplinkURL.url)"); diff --git a/iphone/Maps/Core/Notifications/MWMPushNotifications.h b/iphone/Maps/Core/Notifications/MWMPushNotifications.h index 3fe0fc1282..0069e346b2 100644 --- a/iphone/Maps/Core/Notifications/MWMPushNotifications.h +++ b/iphone/Maps/Core/Notifications/MWMPushNotifications.h @@ -4,19 +4,19 @@ + (void)setup; -+ (void)application:(UIApplication *)application - didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; -+ (void)application:(UIApplication *)application - didFailToRegisterForRemoteNotificationsWithError:(NSError *)error; -+ (void)application:(UIApplication *)application - didReceiveRemoteNotification:(NSDictionary *)userInfo - fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler; -+ (void)userNotificationCenter:(UNUserNotificationCenter *)center - willPresentNotification:(UNNotification *)notification - withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler; -+ (void)userNotificationCenter:(UNUserNotificationCenter *)center -didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void(^)(void))completionHandler; ++ (void)application:(UIApplication *_Nonnull)application +didRegisterForRemoteNotificationsWithDeviceToken:(NSData *_Nonnull)deviceToken; ++ (void)application:(UIApplication *_Nonnull)application +didFailToRegisterForRemoteNotificationsWithError:(NSError *_Nonnull)error; ++ (void)application:(UIApplication *_Nonnull)application +didReceiveRemoteNotification:(NSDictionary *_Nonnull)userInfo +fetchCompletionHandler:(void (^_Nullable)(UIBackgroundFetchResult))completionHandler; ++ (void)userNotificationCenter:(UNUserNotificationCenter *_Nonnull)center + willPresentNotification:(UNNotification *_Nonnull)notification + withCompletionHandler:(void (^_Nullable)(UNNotificationPresentationOptions options))completionHandler; ++ (void)userNotificationCenter:(UNUserNotificationCenter *_Nonnull)center +didReceiveNotificationResponse:(UNNotificationResponse *_Nonnull)response + withCompletionHandler:(void(^_Nullable)(void))completionHandler; + (NSString * _Nonnull)formattedTimestamp; diff --git a/iphone/Maps/UI/AvailableArea/VisibleArea.swift b/iphone/Maps/UI/AvailableArea/VisibleArea.swift index d9bc2f8977..0af554e823 100644 --- a/iphone/Maps/UI/AvailableArea/VisibleArea.swift +++ b/iphone/Maps/UI/AvailableArea/VisibleArea.swift @@ -13,7 +13,7 @@ final class VisibleArea: AvailableArea { if CarPlayService.shared.isCarplayActivated { return } - FrameworkHelper.setVisibleViewport(areaFrame, scaleFactor: MapViewController.shared()?.mapView.contentScaleFactor ?? 1) + FrameworkHelper.setVisibleViewport(areaFrame, scaleFactor: MapViewController.shared()?.mapView.contentScaleFactor ?? 1.0) } } diff --git a/iphone/Maps/UI/PlacePage/Components/GuidesGallery/GuidesGalleryBuilder.swift b/iphone/Maps/UI/PlacePage/Components/GuidesGallery/GuidesGalleryBuilder.swift index c83092dc60..a342197b91 100644 --- a/iphone/Maps/UI/PlacePage/Components/GuidesGallery/GuidesGalleryBuilder.swift +++ b/iphone/Maps/UI/PlacePage/Components/GuidesGallery/GuidesGalleryBuilder.swift @@ -3,7 +3,7 @@ final class GuidesGalleryBuilder: NSObject { @objc static func build() -> GuidesGalleryViewController { let storyboard = UIStoryboard.instance(.placePage) let viewController = storyboard.instantiateViewController(ofType: GuidesGalleryViewController.self); - let router = GuidesGalleryRouter(MapViewController.shared()) + let router = GuidesGalleryRouter(MapViewController.shared()!) let interactor = GuidesGalleryInteractor() let presenter = GuidesGalleryPresenter(view: viewController, router: router, interactor: interactor) viewController.presenter = presenter diff --git a/iphone/Maps/UI/PlacePage/PlacePageBuilder.swift b/iphone/Maps/UI/PlacePage/PlacePageBuilder.swift index d8fbf84e8c..49f003fd6d 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageBuilder.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageBuilder.swift @@ -8,7 +8,7 @@ viewController.isPreviewPlus = data.isPreviewPlus let interactor = PlacePageInteractor(viewController: viewController, data: data, - mapViewController: MapViewController.shared()) + mapViewController: MapViewController.shared()!) let layout:IPlacePageLayout if data.elevationProfileData != nil { layout = PlacePageElevationLayout(interactor: interactor, storyboard: storyboard, data: data) diff --git a/iphone/Maps/UI/PlacePage/PlacePageInteractor.swift b/iphone/Maps/UI/PlacePage/PlacePageInteractor.swift index 3886e684e9..cbae91e36f 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageInteractor.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageInteractor.swift @@ -239,8 +239,9 @@ extension PlacePageInteractor: ActionBarViewControllerDelegate { case .routeTo: MWMPlacePageManagerHelper.route(to: placePageData) case .share: - let shareVC = ActivityViewController.share(forPlacePage: placePageData) - shareVC!.present(inParentViewController: MapViewController.shared(), anchorView: actionBar.popoverSourceView) + if let shareVC = ActivityViewController.share(forPlacePage: placePageData), let mvc = MapViewController.shared() { + shareVC.present(inParentViewController: mvc, anchorView: actionBar.popoverSourceView) + } case .avoidToll: MWMPlacePageManagerHelper.avoidToll() case .avoidDirty: diff --git a/iphone/Maps/UI/PlacePage/PlacePageViewController.swift b/iphone/Maps/UI/PlacePage/PlacePageViewController.swift index c4f2d137d5..f350c7eaf9 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageViewController.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageViewController.swift @@ -24,7 +24,7 @@ final class PlacePageScrollView: UIScrollView { var beginDragging = false var rootViewController: MapViewController { - MapViewController.shared() + MapViewController.shared()! } private var previousTraitCollection: UITraitCollection? diff --git a/iphone/Maps/UI/Search/Tabs/CategoriesTab/SearchCategoriesViewController.swift b/iphone/Maps/UI/Search/Tabs/CategoriesTab/SearchCategoriesViewController.swift index 55ed3ed122..55d8f91753 100644 --- a/iphone/Maps/UI/Search/Tabs/CategoriesTab/SearchCategoriesViewController.swift +++ b/iphone/Maps/UI/Search/Tabs/CategoriesTab/SearchCategoriesViewController.swift @@ -101,6 +101,6 @@ extension SearchCategoriesViewController: SearchBannerCellDelegate { } func cellDidPressClose(_ cell: SearchBannerCell) { - MapViewController.shared().showRemoveAds() + MapViewController.shared()?.showRemoveAds() } } diff --git a/iphone/Maps/UI/Welcome/WhatsNew/WhatsNewBuilder.swift b/iphone/Maps/UI/Welcome/WhatsNew/WhatsNewBuilder.swift index 64f42bdc53..deff276199 100644 --- a/iphone/Maps/UI/Welcome/WhatsNew/WhatsNewBuilder.swift +++ b/iphone/Maps/UI/Welcome/WhatsNew/WhatsNewBuilder.swift @@ -7,10 +7,11 @@ class WhatsNewBuilder { buttonNextTitle: "whatsnew_trial_cta", isCloseButtonHidden: false, action: { - let subscribeViewController = SubscriptionViewBuilder.buildLonelyPlanet(parentViewController: MapViewController.shared(), + guard let mvc = MapViewController.shared() else { return } + let subscribeViewController = SubscriptionViewBuilder.buildLonelyPlanet(parentViewController: mvc, successDialog: .goToCatalog, completion: nil) - MapViewController.shared().present(subscribeViewController, animated: true) + mvc.present(subscribeViewController, animated: true) }), WhatsNewPresenter.WhatsNewConfig(image: UIImage(named: "img_whatsnew_lp"), title: "whatsnew_lp_title",