From 2dbdaf13a4c0615c200895b9b579208cde886d41 Mon Sep 17 00:00:00 2001 From: Alexander Boriskov Date: Fri, 18 Oct 2019 15:09:15 +0300 Subject: [PATCH] [iOS] Convert project to Swift 5 --- .../Catalog/BookmarksSubscriptionButton.swift | 4 ++-- .../Catalog/CatalogWebViewController.swift | 2 +- .../BMCView/BMCViewController.swift | 2 +- .../BMCViewModel/BMCDefaultViewModel.swift | 6 +++--- .../CategorySettingsViewController.swift | 4 ++-- .../BookmarksSharingViewController.swift | 6 +++--- .../Tags/TagsCollectionViewLayout.swift | 4 ++-- iphone/Maps/Categories/Bundle+Init.swift | 2 +- .../Categories/NSAttributedString+HTML.swift | 2 +- .../Maps/Categories/String+BoundingRect.swift | 4 ++-- .../Components/LeftAlignedIconButton.swift | 2 +- .../Modal/AlertPresentationController.swift | 2 +- .../RatingSummaryView/RatingSummaryView.swift | 6 +++--- .../RatingSummaryViewSettings.swift | 2 +- .../Components/RatingView/RatingView.swift | 10 ++++----- .../RatingView/RatingViewSettings.swift | 2 +- .../Classes/Components/TabView/TabView.swift | 4 ++-- .../TabView/TabViewController.swift | 4 ++-- .../BCCreateCategoryAlert.swift | 2 +- .../Views/NavigationControlView.swift | 12 +++++------ .../RouteManagerViewController.swift | 6 +++--- .../BaseRoutePreviewStatus.swift | 2 +- iphone/Maps/Core/Ads/BannersCache.swift | 8 +++---- .../Core/Ads/Facebook/FacebookBanner.swift | 4 ++-- iphone/Maps/Core/Ads/Mopub/MopubBanner.swift | 4 ++-- iphone/Maps/Core/Ads/RB/RBBanner.swift | 4 ++-- .../BackgroundFetchTask.swift | 15 ++++++++----- .../Notifications/NotificationManager.swift | 2 +- iphone/Maps/Maps.xcodeproj/project.pbxproj | 5 ++++- .../Maps/TipsAndTricks/TutorialBlurView.swift | 4 ++-- iphone/Maps/UI/Ads/AdBanner.swift | 6 +++--- .../AuthorizationViewController.swift | 12 +++++------ .../Maps/UI/AvailableArea/AvailableArea.swift | 4 ++-- .../Gallery/GalleryViewController.swift | 2 +- .../Gallery/Photos/PhotoScalingView.swift | 2 +- .../Gallery/Photos/PhotosOverlayView.swift | 2 +- .../Photos/PhotosTransitionAnimator.swift | 2 +- .../Gallery/Photos/PhotosViewController.swift | 21 ++++++++++++++----- .../UGCAddReview/UGCAddReviewController.swift | 4 ++-- .../PlacePageLayout/Preview/PPPReview.swift | 2 +- .../Preview/PPPSearchSimilarButton.swift | 2 +- ...tingsTableViewSelectableProgressCell.swift | 2 +- .../UI/Welcome/TermsOfUseController.swift | 8 +++---- .../UI/Welcome/WelcomePageController.swift | 18 ++++++++++------ 44 files changed, 124 insertions(+), 99 deletions(-) diff --git a/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionButton.swift b/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionButton.swift index 17b576a19c..251a5e8664 100644 --- a/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionButton.swift +++ b/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionButton.swift @@ -23,13 +23,13 @@ class BookmarksSubscriptionButton: UIButton { setTitle("", for: .normal) } - override func setTitleColor(_ color: UIColor?, for state: UIControlState) { + override func setTitleColor(_ color: UIColor?, for state: UIControl.State) { super.setTitleColor(color, for: state) descriptionLabel.textColor = color priceLabel.textColor = color } - override func setTitle(_ title: String?, for state: UIControlState) { + override func setTitle(_ title: String?, for state: UIControl.State) { super.setTitle("", for: state); } diff --git a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift index b00859282f..bc22f4a7ae 100644 --- a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift @@ -22,7 +22,7 @@ final class CatalogWebViewController: WebViewController { UIBlurEffect(style: UIColor.isNightMode() ? .light : .dark)) let progressView = ActivityIndicator() let numberOfTasksLabel = UILabel() - let loadingIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) + let loadingIndicator = UIActivityIndicatorView(style: .gray) let pendingTransactionsHandler = InAppPurchase.pendingTransactionsHandler() var deeplink: URL? var categoryInfo: CatalogCategoryInfo? diff --git a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift index e86c5bbdbc..acb805be15 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift @@ -250,7 +250,7 @@ extension BMCViewController: UITableViewDelegate { } func tableView(_ tableView: UITableView, - commit editingStyle: UITableViewCellEditingStyle, + commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { guard editingStyle == .delete, viewModel.sectionType(section: indexPath.section) == .categories else { diff --git a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift index 0ab8c1b344..bee7e4a7b6 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift @@ -95,7 +95,7 @@ extension BMCDefaultViewModel { } func sectionIndex(section: BMCSection) -> Int { - return sections.index(of: section)! + return sections.firstIndex(of: section)! } func numberOfRows(section: Int) -> Int { @@ -138,7 +138,7 @@ extension BMCDefaultViewModel { } func addCategory(name: String) { - guard let section = sections.index(of: .categories) else { + guard let section = sections.firstIndex(of: .categories) else { assertionFailure() return } @@ -148,7 +148,7 @@ extension BMCDefaultViewModel { } func deleteCategory(at index: Int) { - guard let section = sections.index(of: .categories) else { + guard let section = sections.firstIndex(of: .categories) else { assertionFailure() return } diff --git a/iphone/Maps/Bookmarks/Categories/Category settings/CategorySettingsViewController.swift b/iphone/Maps/Bookmarks/Categories/Category settings/CategorySettingsViewController.swift index f4c150d380..db05253e5f 100644 --- a/iphone/Maps/Bookmarks/Categories/Category settings/CategorySettingsViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/Category settings/CategorySettingsViewController.swift @@ -40,7 +40,7 @@ class CategorySettingsViewController: MWMTableViewController { override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) - if isMovingFromParentViewController && !changesMade { + if isMovingFromParent && !changesMade { Statistics.logEvent(kStatBookmarkSettingsCancel) } } @@ -84,7 +84,7 @@ class CategorySettingsViewController: MWMTableViewController { } override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - return UITableViewAutomaticDimension + return UITableView.automaticDimension } } diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift index c7f2211c0f..74eba9c0b2 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift @@ -51,8 +51,8 @@ final class BookmarksSharingViewController: MWMTableViewController { didSet { let htmlString = String(coreFormat: L("ugc_routes_user_agreement"), arguments: [MWMAuthorizationViewModel.termsOfUseLink()]) - let attributes: [NSAttributedStringKey : Any] = [NSAttributedStringKey.font: UIFont.regular14(), - NSAttributedStringKey.foregroundColor: UIColor.blackSecondaryText()] + let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular14(), + NSAttributedString.Key.foregroundColor: UIColor.blackSecondaryText()] licenseAgreementTextView.attributedText = NSAttributedString.string(withHtml: htmlString, defaultAttributes: attributes) licenseAgreementTextView.delegate = self @@ -100,7 +100,7 @@ final class BookmarksSharingViewController: MWMTableViewController { } override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - return UITableViewAutomaticDimension + return UITableView.automaticDimension } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/Tags/TagsCollectionViewLayout.swift b/iphone/Maps/Bookmarks/Categories/Sharing/Tags/TagsCollectionViewLayout.swift index 786805f026..29f59ccde6 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/Tags/TagsCollectionViewLayout.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/Tags/TagsCollectionViewLayout.swift @@ -43,7 +43,7 @@ final class TagsCollectionViewLayout: UICollectionViewLayout { if showHeaders { let headerSize = headersCache[indexPath]?.size ?? CGSize(width: contentWidth, height: itemHeight) let frame = CGRect(x: 0, y: yOffset, width: headerSize.width, height: headerSize.height) - let attr = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, with: indexPath) + let attr = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, with: indexPath) attr.frame = frame headersCache[indexPath] = attr @@ -99,7 +99,7 @@ final class TagsCollectionViewLayout: UICollectionViewLayout { //dont validate layout if original width already equals to contentWidth - it's the best deal we can offer to cell if preferredAttributes.size.height != originalAttributes.size.height || (preferredAttributes.size.width != originalAttributes.size.width && originalAttributes.size.width < contentWidth) { - if preferredAttributes.representedElementKind == UICollectionElementKindSectionHeader { + if preferredAttributes.representedElementKind == UICollectionView.elementKindSectionHeader { headersCache[originalAttributes.indexPath]?.size = preferredAttributes.size } else { cellsCache[originalAttributes.indexPath]?.size = CGSize(width: min(preferredAttributes.size.width, contentWidth), diff --git a/iphone/Maps/Categories/Bundle+Init.swift b/iphone/Maps/Categories/Bundle+Init.swift index 18a044800f..81708cdfc6 100644 --- a/iphone/Maps/Categories/Bundle+Init.swift +++ b/iphone/Maps/Categories/Bundle+Init.swift @@ -1,6 +1,6 @@ extension Bundle { @objc func load(viewClass: AnyClass, owner: Any? = nil, options: [AnyHashable: Any]? = nil) -> [Any]? { - return loadNibNamed(toString(viewClass), owner: owner, options: options) + return loadNibNamed(toString(viewClass), owner: owner, options: options as! [UINib.OptionsKey : Any]) } @objc func load(plist: String) -> Dictionary? { diff --git a/iphone/Maps/Categories/NSAttributedString+HTML.swift b/iphone/Maps/Categories/NSAttributedString+HTML.swift index 0a6c9d9c83..c4d426ae68 100644 --- a/iphone/Maps/Categories/NSAttributedString+HTML.swift +++ b/iphone/Maps/Categories/NSAttributedString+HTML.swift @@ -1,6 +1,6 @@ extension NSAttributedString { @objc - public class func string(withHtml htmlString:String, defaultAttributes attributes:[NSAttributedStringKey : Any]) -> NSAttributedString? { + public class func string(withHtml htmlString:String, defaultAttributes attributes:[NSAttributedString.Key : Any]) -> NSAttributedString? { guard let data = htmlString.data(using: .utf8) else { return nil } guard let text = try? NSMutableAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, diff --git a/iphone/Maps/Categories/String+BoundingRect.swift b/iphone/Maps/Categories/String+BoundingRect.swift index 3a0225d056..9bfa1f87c9 100644 --- a/iphone/Maps/Categories/String+BoundingRect.swift +++ b/iphone/Maps/Categories/String+BoundingRect.swift @@ -13,8 +13,8 @@ extension String { paragraph.lineBreakMode = .byWordWrapping paragraph.alignment = .natural let attributes = [ - NSAttributedStringKey.font: font, - NSAttributedStringKey.paragraphStyle: paragraph, + NSAttributedString.Key.font: font, + NSAttributedString.Key.paragraphStyle: paragraph, ] var rect = (self as NSString).boundingRect(with: constraintSize, options: options, attributes: attributes, context: nil) var numberOfLines = ceil(rect.height / lineHeight) diff --git a/iphone/Maps/Classes/Components/LeftAlignedIconButton.swift b/iphone/Maps/Classes/Components/LeftAlignedIconButton.swift index 1ab2e7fbd0..3ea3ffc214 100644 --- a/iphone/Maps/Classes/Components/LeftAlignedIconButton.swift +++ b/iphone/Maps/Classes/Components/LeftAlignedIconButton.swift @@ -3,7 +3,7 @@ class LeftAlignedIconButton: UIButton { override func layoutSubviews() { super.layoutSubviews() contentHorizontalAlignment = .left - let availableSpace = UIEdgeInsetsInsetRect(bounds, contentEdgeInsets) + let availableSpace = bounds.inset(by: contentEdgeInsets) let imageWidth = imageView?.frame.width ?? 0 let titleWidth = titleLabel?.frame.width ?? 0 let availableWidth = availableSpace.width - imageEdgeInsets.right - imageWidth * 2 - titleWidth diff --git a/iphone/Maps/Classes/Components/Modal/AlertPresentationController.swift b/iphone/Maps/Classes/Components/Modal/AlertPresentationController.swift index 74af763770..bc3cf43e4c 100644 --- a/iphone/Maps/Classes/Components/Modal/AlertPresentationController.swift +++ b/iphone/Maps/Classes/Components/Modal/AlertPresentationController.swift @@ -1,7 +1,7 @@ final class AlertPresentationController: DimmedModalPresentationController { override var frameOfPresentedViewInContainerView: CGRect { let f = super.frameOfPresentedViewInContainerView - let s = presentedViewController.view.systemLayoutSizeFitting(UILayoutFittingCompressedSize) + let s = presentedViewController.view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) let r = CGRect(x: 0, y: 0, width: s.width, height: s.height) return r.offsetBy(dx: (f.width - r.width) / 2, dy: (f.height - r.height) / 2) } diff --git a/iphone/Maps/Classes/Components/RatingSummaryView/RatingSummaryView.swift b/iphone/Maps/Classes/Components/RatingSummaryView/RatingSummaryView.swift index a6dff3f67e..b1b0a7ed9d 100644 --- a/iphone/Maps/Classes/Components/RatingSummaryView/RatingSummaryView.swift +++ b/iphone/Maps/Classes/Components/RatingSummaryView/RatingSummaryView.swift @@ -279,7 +279,7 @@ import UIKit guard let image = settings.images[type] else { return nil } let imageLayer = createContainerLayer(size) imageLayer.contents = image.cgImage - imageLayer.contentsGravity = kCAGravityResizeAspect + imageLayer.contentsGravity = CALayerContentsGravity.resizeAspect let containerLayer = createContainerLayer(size) if image.renderingMode == .alwaysTemplate { @@ -293,7 +293,7 @@ import UIKit private func createTextLayer() -> CALayer { let font = textFont.withSize(textSize) - let size = NSString(string: value).size(withAttributes: [NSAttributedStringKey.font: font]) + let size = NSString(string: value).size(withAttributes: [NSAttributedString.Key.font: font]) let layer = CATextLayer() layer.bounds = CGRect(origin: CGPoint(), @@ -312,7 +312,7 @@ import UIKit let layer = CALayer() layer.bounds = CGRect(origin: CGPoint(), size: CGSize(width: size, height: size)) layer.anchorPoint = CGPoint() - layer.contentsGravity = kCAGravityResizeAspect + layer.contentsGravity = CALayerContentsGravity.resizeAspect layer.contentsScale = UIScreen.main.scale layer.masksToBounds = true layer.isOpaque = true diff --git a/iphone/Maps/Classes/Components/RatingSummaryView/RatingSummaryViewSettings.swift b/iphone/Maps/Classes/Components/RatingSummaryView/RatingSummaryViewSettings.swift index 6414a200f5..29937468a0 100644 --- a/iphone/Maps/Classes/Components/RatingSummaryView/RatingSummaryViewSettings.swift +++ b/iphone/Maps/Classes/Components/RatingSummaryView/RatingSummaryViewSettings.swift @@ -12,7 +12,7 @@ struct RatingSummaryViewSettings { .excellent: UIColor.blue, ] static let images: [MWMRatingSummaryViewValueType: UIImage] = [:] - static let textFont = UIFont.preferredFont(forTextStyle: UIFontTextStyle.footnote) + static let textFont = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.footnote) static let textSize = textFont.pointSize static let value = "2.2" static let topOffset: CGFloat = 8 diff --git a/iphone/Maps/Classes/Components/RatingView/RatingView.swift b/iphone/Maps/Classes/Components/RatingView/RatingView.swift index 71ea81cc9c..07046e000a 100644 --- a/iphone/Maps/Classes/Components/RatingView/RatingView.swift +++ b/iphone/Maps/Classes/Components/RatingView/RatingView.swift @@ -435,7 +435,7 @@ import UIKit var layers: [RatingViewSettings.TextSide: CALayer] = [:] for (side, text) in texts { let font = settings.textFonts[side]!.withSize(settings.textSizes[side]!) - let size = NSString(string: text).size(withAttributes: [NSAttributedStringKey.font: font]) + let size = NSString(string: text).size(withAttributes: [NSAttributedString.Key.font: font]) let layer = CATextLayer() layer.bounds = CGRect(origin: CGPoint(), @@ -505,7 +505,7 @@ import UIKit let imageLayer = createContainerLayer(size) imageLayer.frame = containerLayer.bounds imageLayer.contents = image.cgImage - imageLayer.contentsGravity = kCAGravityResizeAspect + imageLayer.contentsGravity = CALayerContentsGravity.resizeAspect if image.renderingMode == .alwaysTemplate { containerLayer.mask = imageLayer containerLayer.backgroundColor = (isFilled ? settings.filledColor : settings.emptyColor).cgColor @@ -545,11 +545,11 @@ import UIKit layer.anchorPoint = CGPoint() layer.contentsScale = UIScreen.main.scale layer.strokeColor = strokeColor.cgColor - layer.fillRule = kCAFillRuleEvenOdd + layer.fillRule = CAShapeLayerFillRule.evenOdd layer.fillColor = fillColor.cgColor layer.lineWidth = lineWidth - layer.lineJoin = kCALineJoinRound - layer.lineCap = kCALineCapRound + layer.lineJoin = CAShapeLayerLineJoin.round + layer.lineCap = CAShapeLayerLineCap.round layer.bounds.size = CGSize(width: size, height: size) layer.masksToBounds = true layer.path = path diff --git a/iphone/Maps/Classes/Components/RatingView/RatingViewSettings.swift b/iphone/Maps/Classes/Components/RatingView/RatingViewSettings.swift index 0a5ac75429..edf843ef18 100644 --- a/iphone/Maps/Classes/Components/RatingView/RatingViewSettings.swift +++ b/iphone/Maps/Classes/Components/RatingView/RatingViewSettings.swift @@ -31,7 +31,7 @@ struct RatingViewSettings { static let starMargin: CGFloat = 4 static let starSize: CGFloat = 20 static let textColor = UIColor.lightText - static let textFont = UIFont.preferredFont(forTextStyle: UIFontTextStyle.footnote) + static let textFont = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.footnote) static let textMargin: CGFloat = 4 static let textSize = textFont.pointSize static let starsCount = 5 diff --git a/iphone/Maps/Classes/Components/TabView/TabView.swift b/iphone/Maps/Classes/Components/TabView/TabView.swift index 24385091e5..383fc19a6f 100644 --- a/iphone/Maps/Classes/Components/TabView/TabView.swift +++ b/iphone/Maps/Classes/Components/TabView/TabView.swift @@ -88,7 +88,7 @@ class TabView: UIView { } } - var headerTextAttributes: [NSAttributedStringKey : Any] = [ + var headerTextAttributes: [NSAttributedString.Key : Any] = [ .foregroundColor : UIColor.white, .font : UIFont.systemFont(ofSize: 14, weight: .semibold) ] { @@ -296,7 +296,7 @@ extension TabView : UICollectionViewDelegateFlowLayout { sizeForItemAt indexPath: IndexPath) -> CGSize { var bounds = collectionView.bounds if #available(iOS 11.0, *) { - bounds = UIEdgeInsetsInsetRect(bounds, collectionView.adjustedContentInset) + bounds = bounds.inset(by: collectionView.adjustedContentInset) } if collectionView == tabsContentCollectionView { diff --git a/iphone/Maps/Classes/Components/TabView/TabViewController.swift b/iphone/Maps/Classes/Components/TabView/TabViewController.swift index c983eedcb2..c7a540213b 100644 --- a/iphone/Maps/Classes/Components/TabView/TabViewController.swift +++ b/iphone/Maps/Classes/Components/TabView/TabViewController.swift @@ -2,8 +2,8 @@ class TabViewController: MWMViewController { var viewControllers: [UIViewController] = [] { didSet { viewControllers.forEach { - self.addChildViewController($0) - $0.didMove(toParentViewController: self) + self.addChild($0) + $0.didMove(toParent: self) } } } diff --git a/iphone/Maps/Classes/CustomAlert/CreateBookmarkCategory/BCCreateCategoryAlert.swift b/iphone/Maps/Classes/CustomAlert/CreateBookmarkCategory/BCCreateCategoryAlert.swift index b6ad6b981a..f90d996153 100644 --- a/iphone/Maps/Classes/CustomAlert/CreateBookmarkCategory/BCCreateCategoryAlert.swift +++ b/iphone/Maps/Classes/CustomAlert/CreateBookmarkCategory/BCCreateCategoryAlert.swift @@ -34,7 +34,7 @@ final class BCCreateCategoryAlert: MWMAlert { alert.titleLabel.text = L("bookmarks_create_new_group") let text = L("create").capitalized - for s in [.normal, .highlighted, .disabled] as [UIControlState] { + for s in [.normal, .highlighted, .disabled] as [UIControl.State] { alert.rightButton.setTitle(text, for: s) } diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/NavigationControlView.swift b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/NavigationControlView.swift index fef941f19b..0365fed2d8 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/NavigationControlView.swift +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/NavigationControlView.swift @@ -152,15 +152,15 @@ final class NavigationControlView: SolidTouchView, MWMTextToSpeechObserver, MWMT navigationInfo = info guard !MWMRouter.isTaxi() else { return } - let routingNumberAttributes: [NSAttributedStringKey: Any] = + let routingNumberAttributes: [NSAttributedString.Key: Any] = [ - NSAttributedStringKey.foregroundColor: UIColor.blackPrimaryText(), - NSAttributedStringKey.font: UIFont.bold24(), + NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText(), + NSAttributedString.Key.font: UIFont.bold24(), ] - let routingLegendAttributes: [NSAttributedStringKey: Any] = + let routingLegendAttributes: [NSAttributedString.Key: Any] = [ - NSAttributedStringKey.foregroundColor: UIColor.blackSecondaryText(), - NSAttributedStringKey.font: UIFont.bold14(), + NSAttributedString.Key.foregroundColor: UIColor.blackSecondaryText(), + NSAttributedString.Key.font: UIFont.bold14(), ] if timePageControl.currentPage == 0 { diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RouteManager/RouteManagerViewController.swift b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RouteManager/RouteManagerViewController.swift index 7e830e75a7..c2330e3545 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RouteManager/RouteManagerViewController.swift +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RouteManager/RouteManagerViewController.swift @@ -188,7 +188,7 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource private func setupTableView() { tableView.register(cellClass: RouteManagerCell.self) tableView.estimatedRowHeight = 48 - tableView.rowHeight = UITableViewAutomaticDimension + tableView.rowHeight = UITableView.automaticDimension } @IBAction func onCancel() { @@ -252,12 +252,12 @@ final class RouteManagerViewController: MWMViewController, UITableViewDataSource return cell } - func tableView(_ tableView: UITableView, commit _: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + func tableView(_ tableView: UITableView, commit _: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { viewModel.deletePoint(at: indexPath.row) } // MARK: - UITableViewDelegate - func tableView(_: UITableView, editingStyleForRowAt _: IndexPath) -> UITableViewCellEditingStyle { + func tableView(_: UITableView, editingStyleForRowAt _: IndexPath) -> UITableViewCell.EditingStyle { return canDeleteRow ? .delete : .none } } diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/BaseRoutePreviewStatus.swift b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/BaseRoutePreviewStatus.swift index 7b45ad7ba1..72c84459d6 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/BaseRoutePreviewStatus.swift +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/BaseRoutePreviewStatus.swift @@ -169,7 +169,7 @@ final class BaseRoutePreviewStatus: SolidTouchView { completion: { image, elevation in self.heightProfileImage.image = image guard let elevation = elevation else { return } - let attributes: [NSAttributedStringKey: Any] = + let attributes: [NSAttributedString.Key: Any] = [ .foregroundColor: UIColor.linkBlue(), .font: UIFont.medium14(), diff --git a/iphone/Maps/Core/Ads/BannersCache.swift b/iphone/Maps/Core/Ads/BannersCache.swift index 5fc67b045f..a07f28bace 100644 --- a/iphone/Maps/Core/Ads/BannersCache.swift +++ b/iphone/Maps/Core/Ads/BannersCache.swift @@ -102,12 +102,12 @@ final class BannersCache: NSObject { } private func appendLoadState(_ state: LoadState) { - guard loadStates.index(of: state) == nil else { return } + guard loadStates.firstIndex(of: state) == nil else { return } loadStates.append(state) } private func notLoadedIndex(bannerType: BannerType) -> Array.Index? { - return loadStates.index(where: { + return loadStates.firstIndex(where: { if case let .notLoaded(type) = $0, type == bannerType { return true } @@ -122,7 +122,7 @@ final class BannersCache: NSObject { guard loadStates != nil else { return } - if let notLoadedIndex = loadStates.index(of: .notLoaded(bannerType)) { + if let notLoadedIndex = loadStates.firstIndex(of: .notLoaded(bannerType)) { loadStates[notLoadedIndex] = .loaded(bannerType) } if !cacheOnly { @@ -135,7 +135,7 @@ final class BannersCache: NSObject { guard loadStates != nil else { return } - if let notLoadedIndex = loadStates.index(of: .notLoaded(bannerType)) { + if let notLoadedIndex = loadStates.firstIndex(of: .notLoaded(bannerType)) { loadStates[notLoadedIndex] = .error(bannerType) } if !cacheOnly { diff --git a/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift b/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift index 96169335d9..b68c068611 100644 --- a/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift +++ b/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift @@ -94,11 +94,11 @@ final class FacebookBanner: NSObject, Banner { let center = NotificationCenter.default center.addObserver(self, selector: #selector(enterForeground), - name: .UIApplicationWillEnterForeground, + name: UIApplication.willEnterForegroundNotification, object: nil) center.addObserver(self, selector: #selector(enterBackground), - name: .UIApplicationDidEnterBackground, + name: UIApplication.didEnterBackgroundNotification, object: nil) } diff --git a/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift b/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift index 5fae456135..df8287fd9d 100644 --- a/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift +++ b/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift @@ -59,11 +59,11 @@ final class MopubBanner: NSObject, Banner { let center = NotificationCenter.default center.addObserver(self, selector: #selector(enterForeground), - name: .UIApplicationWillEnterForeground, + name: UIApplication.willEnterForegroundNotification, object: nil) center.addObserver(self, selector: #selector(enterBackground), - name: .UIApplicationDidEnterBackground, + name: UIApplication.didEnterBackgroundNotification, object: nil) } diff --git a/iphone/Maps/Core/Ads/RB/RBBanner.swift b/iphone/Maps/Core/Ads/RB/RBBanner.swift index eeff28fb53..11a8549ba8 100644 --- a/iphone/Maps/Core/Ads/RB/RBBanner.swift +++ b/iphone/Maps/Core/Ads/RB/RBBanner.swift @@ -23,11 +23,11 @@ final class RBBanner: MTRGNativeAd, Banner { let center = NotificationCenter.default center.addObserver(self, selector: #selector(enterForeground), - name: .UIApplicationWillEnterForeground, + name: UIApplication.willEnterForegroundNotification, object: nil) center.addObserver(self, selector: #selector(enterBackground), - name: .UIApplicationDidEnterBackground, + name: UIApplication.didEnterBackgroundNotification, object: nil) } diff --git a/iphone/Maps/Core/BackgroundFetchScheduler/BackgroundFetchTask/BackgroundFetchTask.swift b/iphone/Maps/Core/BackgroundFetchScheduler/BackgroundFetchTask/BackgroundFetchTask.swift index 08de54fb10..527c62efb4 100644 --- a/iphone/Maps/Core/BackgroundFetchScheduler/BackgroundFetchTask/BackgroundFetchTask.swift +++ b/iphone/Maps/Core/BackgroundFetchScheduler/BackgroundFetchTask/BackgroundFetchTask.swift @@ -1,7 +1,7 @@ @objc class BackgroundFetchTask: NSObject { var frameworkType: BackgroundFetchTaskFrameworkType { return .none } - private var backgroundTaskIdentifier = UIBackgroundTaskInvalid + private var backgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid private var completionHandler: BackgroundFetchScheduler.FetchResultHandler? @@ -11,7 +11,7 @@ expirationHandler: { self.finish(.failed) }) - if backgroundTaskIdentifier != UIBackgroundTaskInvalid { fire() } + if backgroundTaskIdentifier != UIBackgroundTaskIdentifier.invalid { fire() } } fileprivate func fire() { @@ -19,9 +19,9 @@ } fileprivate func finish(_ result: UIBackgroundFetchResult) { - guard backgroundTaskIdentifier != UIBackgroundTaskInvalid else { return } - UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier) - backgroundTaskIdentifier = UIBackgroundTaskInvalid + guard backgroundTaskIdentifier != UIBackgroundTaskIdentifier.invalid else { return } + UIApplication.shared.endBackgroundTask(convertToUIBackgroundTaskIdentifier(backgroundTaskIdentifier.rawValue)) + backgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid completionHandler?(result) } } @@ -60,3 +60,8 @@ final class BackgroundUGCUpload: BackgroundFetchTask { return "UGC upload" } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToUIBackgroundTaskIdentifier(_ input: Int) -> UIBackgroundTaskIdentifier { + return UIBackgroundTaskIdentifier(rawValue: input) +} diff --git a/iphone/Maps/Core/Notifications/NotificationManager.swift b/iphone/Maps/Core/Notifications/NotificationManager.swift index 4e2f93b97e..876a8e0f14 100644 --- a/iphone/Maps/Core/Notifications/NotificationManager.swift +++ b/iphone/Maps/Core/Notifications/NotificationManager.swift @@ -12,7 +12,7 @@ final class NotificationManager: NSObject { let notificationContent = UNMutableNotificationContent() notificationContent.title = notification.title notificationContent.body = notification.text - notificationContent.sound = UNNotificationSound.default() + notificationContent.sound = UNNotificationSound.default notificationContent.userInfo = notification.userInfo let notificationRequest = UNNotificationRequest(identifier: notification.identifier, content: notificationContent, diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index c4725b73d6..18acfcfd02 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -4794,7 +4794,7 @@ TargetAttributes = { 6741A93D1BF340DE002C974C = { DevelopmentTeam = N9X2A789QT; - LastSwiftMigration = 0900; + LastSwiftMigration = 1110; ProvisioningStyle = Manual; SystemCapabilities = { com.apple.InAppPurchase = { @@ -5869,6 +5869,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapswithme.full; PROVISIONING_PROFILE_SPECIFIER = "Maps.me Carplay"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -5891,6 +5892,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapswithme.full; PROVISIONING_PROFILE_SPECIFIER = "Maps.me Carplay"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -5910,6 +5912,7 @@ ); LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mapswithme.full; + SWIFT_VERSION = 5.0; }; name = "Production Full"; }; diff --git a/iphone/Maps/TipsAndTricks/TutorialBlurView.swift b/iphone/Maps/TipsAndTricks/TutorialBlurView.swift index 798803456f..924cd3b2f4 100644 --- a/iphone/Maps/TipsAndTricks/TutorialBlurView.swift +++ b/iphone/Maps/TipsAndTricks/TutorialBlurView.swift @@ -6,7 +6,7 @@ class TutorialBlurView: UIVisualEffectView { private let layoutView = UIView(frame: CGRect(x: -100, y: -100, width: 0, height: 0)) private func setup() { - maskLayer.fillRule = kCAFillRuleEvenOdd + maskLayer.fillRule = CAShapeLayerFillRule.evenOdd layer.mask = maskLayer layoutView.translatesAutoresizingMaskIntoConstraints = false layoutView.isUserInteractionEnabled = false @@ -94,7 +94,7 @@ class TutorialBlurView: UIVisualEffectView { animation.fromValue = maskLayer.path animation.toValue = path.cgPath animation.autoreverses = true - animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) + animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) animation.repeatCount = 2 let animationGroup = CAAnimationGroup() diff --git a/iphone/Maps/UI/Ads/AdBanner.swift b/iphone/Maps/UI/Ads/AdBanner.swift index c9c461c28b..a7e17371c8 100644 --- a/iphone/Maps/UI/Ads/AdBanner.swift +++ b/iphone/Maps/UI/Ads/AdBanner.swift @@ -34,9 +34,9 @@ private func attributedTitle(title: String, indent: CGFloat) -> NSAttributedStri paragraphStyle.firstLineHeadIndent = indent paragraphStyle.lineBreakMode = .byTruncatingTail return NSAttributedString(string: title, - attributes: [NSAttributedStringKey.paragraphStyle: paragraphStyle, - NSAttributedStringKey.font: UIFont.bold12(), - NSAttributedStringKey.foregroundColor: UIColor.blackSecondaryText() + attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle, + NSAttributedString.Key.font: UIFont.bold12(), + NSAttributedString.Key.foregroundColor: UIColor.blackSecondaryText() ]) } diff --git a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift index 5f0826d911..f1d090732e 100644 --- a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift +++ b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift @@ -153,8 +153,8 @@ final class AuthorizationViewController: MWMViewController { @IBOutlet private weak var privacyPolicyTextView: UITextView! { didSet { let htmlString = String(coreFormat: L("sign_agree_pp_gdpr"), arguments: [ViewModel.privacyPolicyLink()]) - let attributes: [NSAttributedStringKey : Any] = [NSAttributedStringKey.font: UIFont.regular16(), - NSAttributedStringKey.foregroundColor: UIColor.blackPrimaryText()] + let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular16(), + NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText()] privacyPolicyTextView.attributedText = NSAttributedString.string(withHtml: htmlString, defaultAttributes: attributes) privacyPolicyTextView.delegate = self @@ -164,8 +164,8 @@ final class AuthorizationViewController: MWMViewController { @IBOutlet private weak var termsOfUseTextView: UITextView! { didSet { let htmlString = String(coreFormat: L("sign_agree_tof_gdpr"), arguments: [ViewModel.termsOfUseLink()]) - let attributes: [NSAttributedStringKey : Any] = [NSAttributedStringKey.font: UIFont.regular16(), - NSAttributedStringKey.foregroundColor: UIColor.blackPrimaryText()] + let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular16(), + NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText()] termsOfUseTextView.attributedText = NSAttributedString.string(withHtml: htmlString, defaultAttributes: attributes) termsOfUseTextView.delegate = self @@ -175,8 +175,8 @@ final class AuthorizationViewController: MWMViewController { @IBOutlet private weak var latestNewsTextView: UITextView! { didSet { let text = L("sign_agree_news_gdpr") - let attributes: [NSAttributedStringKey : Any] = [NSAttributedStringKey.font: UIFont.regular16(), - NSAttributedStringKey.foregroundColor: UIColor.blackPrimaryText()] + let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular16(), + NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText()] latestNewsTextView.attributedText = NSAttributedString(string: text, attributes: attributes) } } diff --git a/iphone/Maps/UI/AvailableArea/AvailableArea.swift b/iphone/Maps/UI/AvailableArea/AvailableArea.swift index f2ee96a498..67ab3a5a1b 100644 --- a/iphone/Maps/UI/AvailableArea/AvailableArea.swift +++ b/iphone/Maps/UI/AvailableArea/AvailableArea.swift @@ -55,7 +55,7 @@ class AvailableArea: UIView { UIDevice.current.beginGeneratingDeviceOrientationNotifications() let nc = NotificationCenter.default - nc.addObserver(forName: .UIDeviceOrientationDidChange, object: nil, queue: .main) { _ in + nc.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: .main) { _ in let orientation = UIDevice.current.orientation guard !orientation.isFlat && orientation != .portraitUpsideDown else { return } self.orientation = orientation @@ -102,7 +102,7 @@ class AvailableArea: UIView { func addConstraints(otherView: UIView, directions: MWMAvailableAreaAffectDirections) { precondition(!directions.isEmpty) - let add = { (sa: NSLayoutAttribute, oa: NSLayoutAttribute, rel: NSLayoutRelation) in + let add = { (sa: NSLayoutConstraint.Attribute, oa: NSLayoutConstraint.Attribute, rel: NSLayoutConstraint.Relation) in let c = NSLayoutConstraint(item: self, attribute: sa, relatedBy: rel, toItem: otherView, attribute: oa, multiplier: 1, constant: 0) c.priority = UILayoutPriority.defaultHigh c.isActive = true diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/GalleryViewController.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/GalleryViewController.swift index 1a678f2ff3..fd0686b49c 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/GalleryViewController.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/GalleryViewController.swift @@ -71,7 +71,7 @@ final class GalleryViewController: MWMCollectionViewController { let photoVC = PhotosViewController(photos: model, initialPhoto: currentPhoto, referenceView: cell) photoVC.referenceViewForPhotoWhenDismissingHandler = { [weak self] photo in - if let index = self?.model.items.index(where: { $0 === photo }) { + if let index = self?.model.items.firstIndex(where: { $0 === photo }) { let indexPath = IndexPath(item: index, section: 0) return collectionView.cellForItem(at: indexPath) } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotoScalingView.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotoScalingView.swift index 3ef391ea99..1767f47f26 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotoScalingView.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotoScalingView.swift @@ -43,7 +43,7 @@ final class PhotoScalingView: UIScrollView { showsVerticalScrollIndicator = false showsHorizontalScrollIndicator = false bouncesZoom = true - decelerationRate = UIScrollViewDecelerationRateFast + decelerationRate = UIScrollView.DecelerationRate.fast } private func centerScrollViewContents() { diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosOverlayView.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosOverlayView.swift index 44b93ce6f1..b95c0da834 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosOverlayView.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosOverlayView.swift @@ -13,7 +13,7 @@ final class PhotosOverlayView: UIView { return } guard let photosViewController = photosViewController else { return } - if let index = photosViewController.photos.items.index(where: { $0 === photo }) { + if let index = photosViewController.photos.items.firstIndex(where: { $0 === photo }) { navigationItem.title = "\(index + 1) / \(photosViewController.photos.items.count)" } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosTransitionAnimator.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosTransitionAnimator.swift index 14d98ff3d4..9c64fdb031 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosTransitionAnimator.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosTransitionAnimator.swift @@ -49,7 +49,7 @@ final class PhotosTransitionAnimator: NSObject, UIViewControllerAnimatedTransiti if dismissing { if let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) { - transitionContext.containerView.bringSubview(toFront: fromView) + transitionContext.containerView.bringSubviewToFront(fromView) } } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosViewController.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosViewController.swift index 002fcd324b..8026118f1d 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosViewController.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/Gallery/Photos/PhotosViewController.swift @@ -4,7 +4,7 @@ import UIKit final class PhotosViewController: MWMViewController { @objc var referenceViewForPhotoWhenDismissingHandler: ((GalleryItemModel) -> UIView?)? - private let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: [UIPageViewControllerOptionInterPageSpacingKey: 16.0]) + private let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: convertToOptionalUIPageViewControllerOptionsKeyDictionary([convertFromUIPageViewControllerOptionsKey(UIPageViewController.OptionsKey.interPageSpacing): 16.0])) private(set) var photos: GalleryModel fileprivate let transitionAnimator = PhotosTransitionAnimator() @@ -84,10 +84,10 @@ final class PhotosViewController: MWMViewController { pageViewController.view.addGestureRecognizer(singleTapGestureRecognizer) pageViewController.view.addGestureRecognizer(panGestureRecognizer) - addChildViewController(pageViewController) + addChild(pageViewController) view.addSubview(pageViewController.view) pageViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] - pageViewController.didMove(toParentViewController: self) + pageViewController.didMove(toParent: self) setupOverlayView() } @@ -192,7 +192,7 @@ extension PhotosViewController: UIViewControllerTransitioningDelegate { extension PhotosViewController: UIPageViewControllerDataSource { func pageViewController(_: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { guard let photoViewController = viewController as? PhotoViewController, - let photoIndex = photos.items.index(where: { $0 === photoViewController.photo }), + let photoIndex = photos.items.firstIndex(where: { $0 === photoViewController.photo }), photoIndex - 1 >= 0 else { return nil } @@ -202,7 +202,7 @@ extension PhotosViewController: UIPageViewControllerDataSource { func pageViewController(_: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { guard let photoViewController = viewController as? PhotoViewController, - let photoIndex = photos.items.index(where: { $0 === photoViewController.photo }), + let photoIndex = photos.items.firstIndex(where: { $0 === photoViewController.photo }), photoIndex + 1 < photos.items.count else { return nil } @@ -220,3 +220,14 @@ extension PhotosViewController: UIPageViewControllerDelegate { } } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToOptionalUIPageViewControllerOptionsKeyDictionary(_ input: [String: Any]?) -> [UIPageViewController.OptionsKey: Any]? { + guard let input = input else { return nil } + return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIPageViewController.OptionsKey(rawValue: key), value)}) +} + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertFromUIPageViewControllerOptionsKey(_ input: UIPageViewController.OptionsKey) -> String { + return input.rawValue +} diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift index 953d193aa0..95980a621f 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift @@ -43,7 +43,7 @@ final class UGCAddReviewController: MWMTableViewController { override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) - if isMovingFromParentViewController && !reviewPosted { + if isMovingFromParent && !reviewPosted { Statistics.logEvent(kStatUGCReviewCancel) } } @@ -58,7 +58,7 @@ final class UGCAddReviewController: MWMTableViewController { tableView.register(cellClass: UGCAddReviewTextCell.self) tableView.estimatedRowHeight = 48 - tableView.rowHeight = UITableViewAutomaticDimension + tableView.rowHeight = UITableView.automaticDimension } @objc private func onDone() { diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/PPPReview.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/PPPReview.swift index a03dd881f7..388ea0c535 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/PPPReview.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/PPPReview.swift @@ -93,6 +93,6 @@ final class PPPReview: MWMTableViewCell { override func layoutSubviews() { super.layoutSubviews() let inset = width / 2 - separatorInset = UIEdgeInsetsMake(0, inset, 0, inset) + separatorInset = UIEdgeInsets.init(top: 0, left: inset, bottom: 0, right: inset) } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/PPPSearchSimilarButton.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/PPPSearchSimilarButton.swift index f94f2d211e..ab805ab5a2 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/PPPSearchSimilarButton.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/PPPSearchSimilarButton.swift @@ -15,6 +15,6 @@ final class PPPSearchSimilarButton: MWMTableViewCell { override func layoutSubviews() { super.layoutSubviews() let inset = width / 2 - separatorInset = UIEdgeInsetsMake(0, inset, 0, inset) + separatorInset = UIEdgeInsets.init(top: 0, left: inset, bottom: 0, right: inset) } } diff --git a/iphone/Maps/UI/Settings/Cells/SettingsTableViewSelectableProgressCell.swift b/iphone/Maps/UI/Settings/Cells/SettingsTableViewSelectableProgressCell.swift index be9fc23558..dc13d1aee6 100644 --- a/iphone/Maps/UI/Settings/Cells/SettingsTableViewSelectableProgressCell.swift +++ b/iphone/Maps/UI/Settings/Cells/SettingsTableViewSelectableProgressCell.swift @@ -5,7 +5,7 @@ final class SettingsTableViewSelectableProgressCell: MWMTableViewCell { @objc func config(title: String) { backgroundColor = UIColor.white() - progress.activityIndicatorViewStyle = UIColor.isNightMode() ? .white : .gray + progress.style = UIColor.isNightMode() ? .white : .gray self.title.text = title styleTitle() diff --git a/iphone/Maps/UI/Welcome/TermsOfUseController.swift b/iphone/Maps/UI/Welcome/TermsOfUseController.swift index eebb6dfdf6..55a89444eb 100644 --- a/iphone/Maps/UI/Welcome/TermsOfUseController.swift +++ b/iphone/Maps/UI/Welcome/TermsOfUseController.swift @@ -32,8 +32,8 @@ class TermsOfUseController: WelcomeViewController { @IBOutlet private weak var privacyPolicyTextView: UITextView! { didSet { let htmlString = String(coreFormat: L("sign_agree_pp_gdpr"), arguments: [privacyPolicyLink]) - let attributes: [NSAttributedStringKey : Any] = [NSAttributedStringKey.font: UIFont.regular16(), - NSAttributedStringKey.foregroundColor: UIColor.blackPrimaryText()] + let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular16(), + NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText()] privacyPolicyTextView.attributedText = NSAttributedString.string(withHtml: htmlString, defaultAttributes: attributes) privacyPolicyTextView.delegate = self @@ -43,8 +43,8 @@ class TermsOfUseController: WelcomeViewController { @IBOutlet private weak var termsOfUseTextView: UITextView! { didSet { let htmlString = String(coreFormat: L("sign_agree_tof_gdpr"), arguments: [termsOfUseLink]) - let attributes: [NSAttributedStringKey : Any] = [NSAttributedStringKey.font: UIFont.regular16(), - NSAttributedStringKey.foregroundColor: UIColor.blackPrimaryText()] + let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular16(), + NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText()] termsOfUseTextView.attributedText = NSAttributedString.string(withHtml: htmlString, defaultAttributes: attributes) termsOfUseTextView.delegate = self diff --git a/iphone/Maps/UI/Welcome/WelcomePageController.swift b/iphone/Maps/UI/Welcome/WelcomePageController.swift index d1c2103d1d..d9836d32ff 100644 --- a/iphone/Maps/UI/Welcome/WelcomePageController.swift +++ b/iphone/Maps/UI/Welcome/WelcomePageController.swift @@ -56,7 +56,7 @@ final class WelcomePageController: UIPageViewController { let vc = WelcomePageController(transitionStyle: controllersToShow.count > 1 ? .scroll : .pageCurl, navigationOrientation: .horizontal, - options: [:]) + options: convertToOptionalUIPageViewControllerOptionsKeyDictionary([:])) vc.parentController = parent controllersToShow.forEach { (controller) in controller.delegate = vc @@ -96,7 +96,7 @@ final class WelcomePageController: UIPageViewController { } iPadBackgroundView?.removeFromSuperview() view.removeFromSuperview() - removeFromParentViewController() + removeFromParent() parentController.closePageController(self) FrameworkHelper.processFirstLaunch() } @@ -127,13 +127,13 @@ extension WelcomePageController: UIPageViewControllerDataSource { func pageViewController(_: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { guard viewController != controllers.first else { return nil } - let index = controllers.index(before: controllers.index(of: viewController)!) + let index = controllers.index(before: controllers.firstIndex(of: viewController)!) return controllers[index] } func pageViewController(_: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { guard viewController != controllers.last else { return nil } - let index = controllers.index(after: controllers.index(of: viewController)!) + let index = controllers.index(after: controllers.firstIndex(of: viewController)!) return controllers[index] } @@ -143,13 +143,13 @@ extension WelcomePageController: UIPageViewControllerDataSource { func presentationIndex(for _: UIPageViewController) -> Int { guard let vc = currentController else { return 0 } - return controllers.index(of: vc)! + return controllers.firstIndex(of: vc)! } } extension WelcomePageController: WelcomeViewControllerDelegate { func welcomeViewControllerDidPressNext(_ viewContoller: WelcomeViewController) { - guard let index = controllers.index(of: viewContoller) else { + guard let index = controllers.firstIndex(of: viewContoller) else { close() return } @@ -182,3 +182,9 @@ extension WelcomePageController: DeeplinkInfoViewControllerDelegate { DeepLinkHandler.shared.handleDeeplink(dl) } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToOptionalUIPageViewControllerOptionsKeyDictionary(_ input: [String: Any]?) -> [UIPageViewController.OptionsKey: Any]? { + guard let input = input else { return nil } + return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIPageViewController.OptionsKey(rawValue: key), value)}) +}