From 06e9ebd3043598583503f61743e2bec4b6ed76b1 Mon Sep 17 00:00:00 2001 From: rrulin Date: Sun, 8 Oct 2017 22:08:16 +0300 Subject: [PATCH 1/2] Migrated to Swift 4 --- YouTube.xcodeproj/project.pbxproj | 21 ++++++++++++++++++--- YouTube/Extensions/extensions.swift | 2 +- YouTube/Supporting views/PlayerView.swift | 4 ++-- YouTube/Supporting views/TabBarView.swift | 2 +- YouTube/ViewControllers/MainVC.swift | 4 ++-- YouTube/ViewControllers/NavVC.swift | 6 +++--- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/YouTube.xcodeproj/project.pbxproj b/YouTube.xcodeproj/project.pbxproj index 9de34db..3f0b345 100644 --- a/YouTube.xcodeproj/project.pbxproj +++ b/YouTube.xcodeproj/project.pbxproj @@ -167,13 +167,14 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0800; - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Haik Aslanyan"; TargetAttributes = { 22AA44621D1302FB00CA6185 = { CreatedOnToolsVersion = 8.0; DevelopmentTeam = P6GDVV24N5; DevelopmentTeamName = "Haik Aslanyan (Personal Team)"; + LastSwiftMigration = 0900; ProvisioningStyle = Automatic; }; }; @@ -254,7 +255,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -262,7 +265,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -303,7 +310,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -311,7 +320,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -348,7 +361,8 @@ PRODUCT_BUNDLE_IDENTIFIER = com.haik.YouTube; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 1; }; name = Debug; @@ -365,7 +379,8 @@ PRODUCT_BUNDLE_IDENTIFIER = com.haik.YouTube; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 1; }; name = Release; diff --git a/YouTube/Extensions/extensions.swift b/YouTube/Extensions/extensions.swift index 405f696..1056fa4 100644 --- a/YouTube/Extensions/extensions.swift +++ b/YouTube/Extensions/extensions.swift @@ -37,7 +37,7 @@ extension MutableCollection where Index == Int { for i in startIndex ..< endIndex - 1 { let j = Int(arc4random_uniform(UInt32(endIndex - i))) + i if i != j { - swap(&self[i], &self[j]) + self.swapAt(i, j) } } } diff --git a/YouTube/Supporting views/PlayerView.swift b/YouTube/Supporting views/PlayerView.swift index 9e8e0e1..fdbc93d 100644 --- a/YouTube/Supporting views/PlayerView.swift +++ b/YouTube/Supporting views/PlayerView.swift @@ -84,7 +84,7 @@ class PlayerView: UIView, UITableViewDelegate, UITableViewDataSource, UIGestureR self.player.transform = trasform } - func tapPlayView() { + @objc func tapPlayView() { self.videoPlayer.play() self.state = .fullScreen self.delegate?.didmaximize() @@ -180,7 +180,7 @@ class PlayerView: UIView, UITableViewDelegate, UITableViewDataSource, UIGestureR weakSelf.videoPlayer = AVPlayer.init(url: weakSelf.video.videoLink) let playerLayer = AVPlayerLayer.init(player: weakSelf.videoPlayer) playerLayer.frame = weakSelf.player.frame - playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill + playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill weakSelf.player.layer.addSublayer(playerLayer) if weakSelf.state != .hidden { diff --git a/YouTube/Supporting views/TabBarView.swift b/YouTube/Supporting views/TabBarView.swift index bfed624..7ed3803 100644 --- a/YouTube/Supporting views/TabBarView.swift +++ b/YouTube/Supporting views/TabBarView.swift @@ -39,7 +39,7 @@ class TabBarView: UIView, UICollectionViewDelegateFlowLayout, UICollectionViewDa NotificationCenter.default.addObserver(self, selector: #selector(self.animateMenu(notification:)), name: Notification.Name.init(rawValue: "scrollMenu"), object: nil) } - func animateMenu(notification: Notification) { + @objc func animateMenu(notification: Notification) { if let info = notification.userInfo { let userInfo = info as! [String: CGFloat] self.whiteBarLeadingConstraint.constant = self.whiteBar.bounds.width * userInfo["length"]! diff --git a/YouTube/ViewControllers/MainVC.swift b/YouTube/ViewControllers/MainVC.swift index def5edb..ea3f792 100644 --- a/YouTube/ViewControllers/MainVC.swift +++ b/YouTube/ViewControllers/MainVC.swift @@ -60,14 +60,14 @@ class MainVC: UIViewController, UICollectionViewDataSource, UICollectionViewDele NotificationCenter.default.addObserver(self, selector: #selector(self.hideBar(notification:)), name: NSNotification.Name("hide"), object: nil) } - func scrollViews(notification: Notification) { + @objc func scrollViews(notification: Notification) { if let info = notification.userInfo { let userInfo = info as! [String: Int] self.collectionView.scrollToItem(at: IndexPath.init(row: userInfo["index"]!, section: 0), at: .centeredHorizontally, animated: true) } } - func hideBar(notification: NSNotification) { + @objc func hideBar(notification: NSNotification) { let state = notification.object as! Bool self.navigationController?.setNavigationBarHidden(state, animated: true) } diff --git a/YouTube/ViewControllers/NavVC.swift b/YouTube/ViewControllers/NavVC.swift index 54248a5..90d32a2 100755 --- a/YouTube/ViewControllers/NavVC.swift +++ b/YouTube/ViewControllers/NavVC.swift @@ -107,7 +107,7 @@ class NavVC: UINavigationController, PlayerVCDelegate { NotificationCenter.default.addObserver(self, selector: #selector(self.changeTitle(notification:)), name: Notification.Name.init(rawValue: "scrollMenu"), object: nil) } - func showSearch() { + @objc func showSearch() { self.searchView.alpha = 0 self.searchView.isHidden = false UIView.animate(withDuration: 0.2, animations: { @@ -117,7 +117,7 @@ class NavVC: UINavigationController, PlayerVCDelegate { } } - func showSettings() { + @objc func showSettings() { self.settingsView.isHidden = false self.settingsView.tableViewBottomConstraint.constant = 0 UIView.animate(withDuration: 0.3) { @@ -126,7 +126,7 @@ class NavVC: UINavigationController, PlayerVCDelegate { } } - func changeTitle(notification: Notification) { + @objc func changeTitle(notification: Notification) { if let info = notification.userInfo { let userInfo = info as! [String: CGFloat] self.titleLabel.text = self.names[Int(round(userInfo["length"]!))] From e0e96c1616a7da977a91f1299c7ca36b9e4e08ee Mon Sep 17 00:00:00 2001 From: rrulin Date: Sun, 8 Oct 2017 22:14:48 +0300 Subject: [PATCH 2/2] Changed Swift 3 @objc Inference to Default --- YouTube.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/YouTube.xcodeproj/project.pbxproj b/YouTube.xcodeproj/project.pbxproj index 3f0b345..8abd283 100644 --- a/YouTube.xcodeproj/project.pbxproj +++ b/YouTube.xcodeproj/project.pbxproj @@ -361,7 +361,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.haik.YouTube; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 1; }; @@ -379,7 +379,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.haik.YouTube; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 1; };