Skip to content

Commit

Permalink
Upgrade to Swift 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 11, 2019
1 parent 16587a9 commit 43e95e7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 65 deletions.
26 changes: 10 additions & 16 deletions Blear.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -28,6 +28,7 @@
923B260222CB8281001181DC /* JGProgressHUDShadow.m in Sources */ = {isa = PBXBuildFile; fileRef = 923B25EF22CB8281001181DC /* JGProgressHUDShadow.m */; };
E33A6D501B2272B700CBEDC9 /* UIImageEffects.m in Sources */ = {isa = PBXBuildFile; fileRef = E33A6D4F1B2272B700CBEDC9 /* UIImageEffects.m */; };
E3430F431B27AD5800AF3F80 /* Bundled Photos in Resources */ = {isa = PBXBuildFile; fileRef = E3430F421B27AD5800AF3F80 /* Bundled Photos */; };
E37D72AE2329664C008B1C48 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37D72AD2329664B008B1C48 /* Constants.swift */; };
E3A0365A17E5E7AE00892B76 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A0365917E5E7AE00892B76 /* AppDelegate.swift */; };
E3A0365C17E5E7AE00892B76 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E3A0365B17E5E7AE00892B76 /* Images.xcassets */; };
E3A0367A17E5E94E00892B76 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A0367917E5E94E00892B76 /* ViewController.swift */; };
Expand Down Expand Up @@ -71,6 +72,7 @@
E33A6D4E1B2272B700CBEDC9 /* UIImageEffects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIImageEffects.h; sourceTree = "<group>"; };
E33A6D4F1B2272B700CBEDC9 /* UIImageEffects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIImageEffects.m; sourceTree = "<group>"; };
E3430F421B27AD5800AF3F80 /* Bundled Photos */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Bundled Photos"; sourceTree = "<group>"; };
E37D72AD2329664B008B1C48 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Constants.swift; sourceTree = "<group>"; usesTabs = 1; };
E3A0364617E5E7AE00892B76 /* Blear.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Blear.app; sourceTree = BUILT_PRODUCTS_DIR; };
E3A0365117E5E7AE00892B76 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E3A0365917E5E7AE00892B76 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AppDelegate.swift; sourceTree = "<group>"; usesTabs = 1; };
Expand Down Expand Up @@ -147,20 +149,12 @@
path = JGProgressHUD;
sourceTree = "<group>";
};
BA30F9B1BA4BBAB35BCD89A2 /* Pods */ = {
isa = PBXGroup;
children = (
);
path = Pods;
sourceTree = "<group>";
};
E3A0363D17E5E7AE00892B76 = {
isa = PBXGroup;
children = (
E3A0364F17E5E7AE00892B76 /* Blear */,
E3B0ED1522CCE084001D4F9E /* Vendor */,
E3A0364717E5E7AE00892B76 /* Products */,
BA30F9B1BA4BBAB35BCD89A2 /* Pods */,
);
sourceTree = "<group>";
};
Expand All @@ -176,6 +170,7 @@
isa = PBXGroup;
children = (
E3A0365917E5E7AE00892B76 /* AppDelegate.swift */,
E37D72AD2329664B008B1C48 /* Constants.swift */,
E3A0367917E5E94E00892B76 /* ViewController.swift */,
E3A0368E17E6214500892B76 /* util.swift */,
E3A0365B17E5E7AE00892B76 /* Images.xcassets */,
Expand Down Expand Up @@ -251,7 +246,7 @@
};
};
buildConfigurationList = E3A0364117E5E7AE00892B76 /* Build configuration list for PBXProject "Blear" */;
compatibilityVersion = "Xcode 10.0";
compatibilityVersion = "Xcode 11.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down Expand Up @@ -311,6 +306,7 @@
buildActionMask = 2147483647;
files = (
923B25FB22CB8281001181DC /* JGProgressHUDImageIndicatorView.m in Sources */,
E37D72AE2329664C008B1C48 /* Constants.swift in Sources */,
E3A0367A17E5E94E00892B76 /* ViewController.swift in Sources */,
923B25FE22CB8281001181DC /* JGProgressHUD.m in Sources */,
E3A0365A17E5E7AE00892B76 /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -378,10 +374,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -425,11 +421,11 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -453,7 +449,6 @@
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OBJC_BRIDGING_HEADER = "Blear/Blear-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -475,7 +470,6 @@
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Blear/Blear-Bridging-Header.h";
SWIFT_VERSION = 5.0;
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down
7 changes: 4 additions & 3 deletions Blear/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import UIKit

@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {
let window = UIWindow(frame: UIScreen.main.bounds)
var window: UIWindow?

func applicationDidFinishLaunching(_ application: UIApplication) {
window.rootViewController = ViewController()
window.makeKeyAndVisible()
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
}
}
7 changes: 7 additions & 0 deletions Blear/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

let IS_IPAD = UIDevice().userInterfaceIdiom == .pad
let IS_IPHONE = UIDevice().userInterfaceIdiom == .phone
let SCREEN_WIDTH = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT = UIScreen.main.bounds.size.height
let IS_LARGE_SCREEN = IS_IPHONE && max(SCREEN_WIDTH, SCREEN_HEIGHT) >= 736.0
41 changes: 8 additions & 33 deletions Blear/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@ import UIKit
import Photos
import MobileCoreServices

let IS_IPAD = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad
let IS_IPHONE = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone
let SCREEN_WIDTH = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT = UIScreen.main.bounds.size.height
let IS_LARGE_SCREEN = IS_IPHONE && max(SCREEN_WIDTH, SCREEN_HEIGHT) >= 736.0

// TODO: Use `@propertyWrapper` for this when it's out.
extension UserDefaults {
var showedScrollPreview: Bool {
let key = "__showedScrollPreview__"

if bool(forKey: key) {
return false
} else {
set(true, forKey: key)
return true
}
}
}

final class ViewController: UIViewController {
var sourceImage: UIImage?
var blurAmount: Float = 50
Expand Down Expand Up @@ -62,16 +42,12 @@ final class ViewController: UIViewController {
]
$0.addTarget(self, action: #selector(sliderChanged), for: .valueChanged)
}

var saveBarButton: UIBarButtonItem!

override var canBecomeFirstResponder: Bool {
return true
}
override var canBecomeFirstResponder: Bool { true }

override var prefersStatusBarHidden: Bool {
return true
}
override var prefersStatusBarHidden: Bool { true }

override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if motion == .motionShake {
Expand Down Expand Up @@ -116,7 +92,7 @@ final class ViewController: UIViewController {
]
view.addSubview(toolbar)

// Important that this is here at the end for the fading to work
// Important that this is here at the end for the fading to work.
randomImage()
}

Expand All @@ -134,7 +110,7 @@ final class ViewController: UIViewController {
self.previewScrollingToUser()
})

self.present(alert, animated: true)
present(alert, animated: true)
}
}

Expand Down Expand Up @@ -168,7 +144,7 @@ final class ViewController: UIViewController {
}

func blurImage(_ blurAmount: Float) -> UIImage {
return UIImageEffects.imageByApplyingBlur(
UIImageEffects.imageByApplyingBlur(
to: sourceImage,
withRadius: CGFloat(blurAmount * (IS_LARGE_SCREEN ? 0.8 : 1.2)),
tintColor: UIColor(white: 1, alpha: CGFloat(max(0, min(0.25, blurAmount * 0.004)))),
Expand Down Expand Up @@ -220,11 +196,10 @@ final class ViewController: UIViewController {
return
}

//HUD.indicatorView = JGProgressHUDImageIndicatorView(image: #imageLiteral(resourceName: "HudSaved"))
HUD.show(in: self.view)
HUD.dismiss(afterDelay: 0.8)

// Only on first save
// Only on first save.
if UserDefaults.standard.isFirstLaunch {
delay(seconds: 1) {
let alert = UIAlertController(
Expand All @@ -250,7 +225,7 @@ final class ViewController: UIViewController {
sourceImage = image.resized(to: CGSize(width: imageViewSize.width / 2, height: imageViewSize.height / 2))
updateImage()

// The delay here is important so it has time to blur the image before we start fading
// The delay here is important so it has time to blur the image before we start fading.
UIView.animate(
withDuration: 0.6,
delay: 0.3,
Expand Down
20 changes: 8 additions & 12 deletions Blear/util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ extension UserDefaults {
}

extension UIImage {
/// Initialize with a URL
/// AppKit.NSImage polyfill
/// Initialize with a URL.
/// `AppKit.NSImage` polyfill.
convenience init?(contentsOf url: URL) {
self.init(contentsOfFile: url.path)
}
Expand All @@ -222,17 +222,17 @@ extension UIImage {
}

func resized(to size: CGSize) -> UIImage {
return UIGraphicsImageRenderer(size: size).image { _ in
UIGraphicsImageRenderer(size: size).image { _ in
draw(in: CGRect(origin: .zero, size: size))
}
}
}

extension UIView {
/// The most efficient solution
/// The most efficient solution.
@objc
func toImage() -> UIImage {
return UIGraphicsImageRenderer(size: bounds.size).image { _ in
UIGraphicsImageRenderer(size: bounds.size).image { _ in
self.drawHierarchy(in: bounds, afterScreenUpdates: true)
}
}
Expand All @@ -247,21 +247,17 @@ extension UIEdgeInsets {
self.init(top: vertical, left: horizontal, bottom: vertical, right: horizontal)
}

func inset(rect: CGRect) -> CGRect {
return rect.inset(by: self)
}
func inset(rect: CGRect) -> CGRect { rect.inset(by: self) }
}

extension UIViewController {
var window: UIWindow {
return UIApplication.shared.windows.first!
}
var window: UIWindow { UIApplication.shared.windows.first! }
}

extension UIScrollView {
@objc
override func toImage() -> UIImage {
return UIGraphicsImageRenderer(size: bounds.size).image { _ in
UIGraphicsImageRenderer(size: bounds.size).image { _ in
let newBounds = bounds.offsetBy(dx: -contentOffset.x, dy: -contentOffset.y)
self.drawHierarchy(in: newBounds, afterScreenUpdates: true)
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

## Info

Requires minimum iOS 12.2.
Requires minimum iOS 13.

0 comments on commit 43e95e7

Please sign in to comment.