From a9a43fe0235f33ff31c687502b1952f807e46d57 Mon Sep 17 00:00:00 2001 From: Matt Long Date: Mon, 23 Oct 2017 13:53:43 -0600 Subject: [PATCH] Update to Xcode 9/Swift 4 --- .../project.pbxproj | 4 ++++ .../AppDelegate.swift | 12 +++++------ .../AppIcon.appiconset/Contents.json | 15 ++++++++++++++ .../Base.lproj/LaunchScreen.storyboard | 14 ++++++++----- .../Base.lproj/Main.storyboard | 16 +++++++++------ .../DemoController.swift | 20 +++++++++---------- .../PreviewControllerToolbar.swift | 2 +- .../PreviewNavigationController.swift | 10 +++++----- 8 files changed, 60 insertions(+), 33 deletions(-) diff --git a/PreviewControllerHideBottomButtons.xcodeproj/project.pbxproj b/PreviewControllerHideBottomButtons.xcodeproj/project.pbxproj index c007ddf..e965a39 100644 --- a/PreviewControllerHideBottomButtons.xcodeproj/project.pbxproj +++ b/PreviewControllerHideBottomButtons.xcodeproj/project.pbxproj @@ -138,6 +138,7 @@ TargetAttributes = { C7A9FB7D1D7A0C4500579DEC = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0820; }; }; }; @@ -301,6 +302,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.example.PreviewControllerHideBottomButtons; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -312,6 +314,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.example.PreviewControllerHideBottomButtons; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -334,6 +337,7 @@ C7A9FB921D7A0C4500579DEC /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/PreviewControllerHideBottomButtons/AppDelegate.swift b/PreviewControllerHideBottomButtons/AppDelegate.swift index fe636e0..bd0a7bc 100644 --- a/PreviewControllerHideBottomButtons/AppDelegate.swift +++ b/PreviewControllerHideBottomButtons/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } } diff --git a/PreviewControllerHideBottomButtons/Assets.xcassets/AppIcon.appiconset/Contents.json b/PreviewControllerHideBottomButtons/Assets.xcassets/AppIcon.appiconset/Contents.json index 4f9f6be..9e21027 100644 --- a/PreviewControllerHideBottomButtons/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/PreviewControllerHideBottomButtons/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "size" : "29x29", "idiom" : "iphone", @@ -35,6 +45,11 @@ "idiom" : "iphone", "filename" : "Icon-60@3x.png", "scale" : "3x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/PreviewControllerHideBottomButtons/Base.lproj/LaunchScreen.storyboard b/PreviewControllerHideBottomButtons/Base.lproj/LaunchScreen.storyboard index 5bc8b47..c0c6e6e 100644 --- a/PreviewControllerHideBottomButtons/Base.lproj/LaunchScreen.storyboard +++ b/PreviewControllerHideBottomButtons/Base.lproj/LaunchScreen.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,9 +18,9 @@ - + - + diff --git a/PreviewControllerHideBottomButtons/Base.lproj/Main.storyboard b/PreviewControllerHideBottomButtons/Base.lproj/Main.storyboard index 11cf791..9c1aa78 100644 --- a/PreviewControllerHideBottomButtons/Base.lproj/Main.storyboard +++ b/PreviewControllerHideBottomButtons/Base.lproj/Main.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,11 +18,11 @@ - + - + diff --git a/PreviewControllerHideBottomButtons/DemoController.swift b/PreviewControllerHideBottomButtons/DemoController.swift index 0d057ec..02ff093 100644 --- a/PreviewControllerHideBottomButtons/DemoController.swift +++ b/PreviewControllerHideBottomButtons/DemoController.swift @@ -11,7 +11,7 @@ import QuickLook class DemoController: UIViewController { - private let itemsArray:[String] = ["image1", "image2", "image3"] + fileprivate let itemsArray:[String] = ["image1", "image2", "image3"] override func viewDidLoad() { super.viewDidLoad() @@ -25,14 +25,14 @@ class DemoController: UIViewController { //MARK: - IBActions extension DemoController { - @IBAction func presentPreviewControllerTapped(sender: UIButton) { + @IBAction func presentPreviewControllerTapped(_ sender: UIButton) { let previewController = QLPreviewController() previewController.dataSource = self let previewNavigationController = PreviewNavigationController(navigationBarClass:nil, toolbarClass: PreviewControllerToolbar.self) previewNavigationController.pushViewController(previewController, animated: false) - presentViewController(previewNavigationController, animated:true, completion: nil) + present(previewNavigationController, animated:true, completion: nil) } } @@ -41,17 +41,17 @@ extension DemoController { //MARK: - QLPreviewControllerDataSource extension DemoController : QLPreviewControllerDataSource { - func numberOfPreviewItemsInPreviewController(controller: QLPreviewController) -> Int { + func numberOfPreviewItems(in controller: QLPreviewController) -> Int { return itemsArray.count } - func previewController(controller: QLPreviewController, previewItemAtIndex index: Int) -> QLPreviewItem { + func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { - guard let filePath = NSBundle.mainBundle().pathForResource(itemsArray[index], ofType:"jpg") else { - return NSURL() + guard let filePath = Bundle.main.path(forResource: itemsArray[index], ofType:"jpg") else { + return URL(fileURLWithPath: "bob") as QLPreviewItem } - let url = NSURL.fileURLWithPath(filePath) - return url + let url = URL(fileURLWithPath: filePath) + return url as QLPreviewItem } -} \ No newline at end of file +} diff --git a/PreviewControllerHideBottomButtons/PreviewControllerToolbar.swift b/PreviewControllerHideBottomButtons/PreviewControllerToolbar.swift index cee3fe1..f8abcef 100644 --- a/PreviewControllerHideBottomButtons/PreviewControllerToolbar.swift +++ b/PreviewControllerHideBottomButtons/PreviewControllerToolbar.swift @@ -10,7 +10,7 @@ import UIKit class PreviewControllerToolbar: UIToolbar { - override func setItems(items: [UIBarButtonItem]?, animated: Bool) { + override func setItems(_ items: [UIBarButtonItem]?, animated: Bool) { super.setItems([], animated: false) } } diff --git a/PreviewControllerHideBottomButtons/PreviewNavigationController.swift b/PreviewControllerHideBottomButtons/PreviewNavigationController.swift index 52b66a1..b30b22b 100644 --- a/PreviewControllerHideBottomButtons/PreviewNavigationController.swift +++ b/PreviewControllerHideBottomButtons/PreviewNavigationController.swift @@ -14,11 +14,11 @@ class PreviewNavigationController: UINavigationController { super.viewDidLoad() } - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if let controller = viewControllers.first { - let doneButton = UIBarButtonItem(barButtonSystemItem: .Done, target:self, action:#selector(doneButtonTapped)) + let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target:self, action:#selector(doneButtonTapped)) controller.navigationItem.leftBarButtonItem = doneButton } } @@ -31,7 +31,7 @@ class PreviewNavigationController: UINavigationController { extension PreviewNavigationController { - func doneButtonTapped() -> Void { - dismissViewControllerAnimated(true, completion: nil) + @objc func doneButtonTapped() -> Void { + dismiss(animated: true, completion: nil) } -} \ No newline at end of file +}