Skip to content
Permalink
Browse files

Swift 5 migration

  • Loading branch information...
GianniCarlo committed Mar 27, 2019
1 parent 6c2ce59 commit cf90a2d6ad5314e3fe8b3224c71988160324ec41
@@ -8,3 +8,4 @@ disabled_rules:
- switch_case_alignment
- identifier_name
- trailing_comma
- private_over_fileprivate
@@ -797,7 +797,7 @@
418B6CF71D2707F800F974FB = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = S7TJSJXWUZ;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
enabled = 1;
@@ -818,14 +818,14 @@
};
418B6D0D1D2707F800F974FB = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
TestTargetID = 418B6CF71D2707F800F974FB;
};
};
};
buildConfigurationList = 418B6CF31D2707F700F974FB /* Build configuration list for PBXProject "BookPlayer" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
@@ -1245,8 +1245,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.tortugapower.audiobookplayer;
PRODUCT_NAME = BookPlayer;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
@@ -1272,8 +1271,7 @@
PRODUCT_NAME = BookPlayer;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = RELEASE;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
@@ -1287,8 +1285,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.tortugapower.Audiobook-PlayerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BookPlayer.app/BookPlayer";
};
name = Debug;
@@ -1302,8 +1299,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.tortugapower.Audiobook-PlayerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BookPlayer.app/BookPlayer";
};
name = Release;
@@ -1380,8 +1376,7 @@
PRODUCT_NAME = BookPlayer;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = RELEASE;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Beta;
@@ -1395,8 +1390,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.tortugapower.Audiobook-PlayerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BookPlayer.app/BookPlayer";
};
name = Beta;
@@ -19,7 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var wasPlayingBeforeInterruption: Bool = false
var watcher: DirectoryWatcher?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let defaults: UserDefaults = UserDefaults.standard

@@ -33,22 +33,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// Appearance
UINavigationBar.appearance().titleTextAttributes = [
NSAttributedStringKey.foregroundColor: UIColor(hex: "#37454E")
NSAttributedString.Key.foregroundColor: UIColor(hex: "#37454E")
]

if #available(iOS 11, *) {
UINavigationBar.appearance().largeTitleTextAttributes = [
NSAttributedStringKey.foregroundColor: UIColor(hex: "#37454E")
NSAttributedString.Key.foregroundColor: UIColor(hex: "#37454E")
]
}

try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeSpokenAudio, options: [])
try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: AVAudioSession.Mode(rawValue: convertFromAVAudioSessionMode(AVAudioSession.Mode.spokenAudio)), options: [])

// register to audio-interruption notifications
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioInterruptions(_:)), name: NSNotification.Name.AVAudioSessionInterruption, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioInterruptions(_:)), name: AVAudioSession.interruptionNotification, object: nil)

// register to audio-route-change notifications
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioRouteChange(_:)), name: NSNotification.Name.AVAudioSessionRouteChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioRouteChange(_:)), name: AVAudioSession.routeChangeNotification, object: nil)

// register for remote events
self.setupMPRemoteCommands()
@@ -59,22 +59,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// setup store required listeners
self.setupStoreListener()

if let activityDictionary = launchOptions?[.userActivityDictionary] as? [UIApplicationLaunchOptionsKey: Any],
if let activityDictionary = launchOptions?[.userActivityDictionary] as? [UIApplication.LaunchOptionsKey: Any],
let activityType = activityDictionary[.userActivityType] as? String,
activityType == Constants.UserActivityPlayback {
defaults.set(true, forKey: activityType)
}

// Create a Sentry client and start crash handler
Client.shared = try? Client(dsn: "https://23b4d02f7b044c10adb55a0cc8de3881@sentry.io/1414296")
try? Client.shared?.startCrashHandler()
((try? Client.shared?.startCrashHandler()) as ()??)

return true
}

// Handles audio file urls, like when receiving files through AirDrop
// Also handles custom URL scheme 'bookplayer://'
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
guard url.isFileURL else {
self.playLastBook()
return true
@@ -85,7 +85,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
PlayerManager.shared.play()
return true
}
@@ -115,7 +115,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Check if the app is on the PlayerViewController
// TODO: Check if this still works as expected given the new storyboard structure
guard let navigationVC = UIApplication.shared.keyWindow?.rootViewController!, navigationVC.childViewControllers.count > 1 else {
guard let navigationVC = UIApplication.shared.keyWindow?.rootViewController!, navigationVC.children.count > 1 else {
return
}

@@ -143,7 +143,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
@objc func handleAudioInterruptions(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
let type = AVAudioSessionInterruptionType(rawValue: typeValue) else {
let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
return
}

@@ -157,10 +157,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return
}

let options = AVAudioSessionInterruptionOptions(rawValue: optionsValue)
let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
if options.contains(.shouldResume) {
PlayerManager.shared.play()
}
@unknown default:
break
}
}

@@ -169,7 +171,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
guard PlayerManager.shared.isPlaying,
let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue: reasonValue) else {
let reason = AVAudioSession.RouteChangeReason(rawValue: reasonValue) else {
return
}

@@ -283,3 +285,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromAVAudioSessionMode(_ input: AVAudioSession.Mode) -> String {
return input.rawValue
}
@@ -390,7 +390,7 @@ extension UIColor {
var h_p: CGFloat = 0
if (C_1_p * C_2_p) == 0 {
h_p = 0
} else if fabs(h_2_p - h_1_p) <= 180 {
} else if abs(h_2_p - h_1_p) <= 180 {
h_p = h_2_p - h_1_p
} else if (h_2_p - h_1_p) > 180 {
h_p = h_2_p - h_1_p - 360
@@ -406,11 +406,11 @@ extension UIColor {
var h_p_bar: CGFloat = 0
if (h_1_p * h_2_p) == 0 {
h_p_bar = h_1_p + h_2_p
} else if fabs(h_1_p - h_2_p) <= 180 {
} else if abs(h_1_p - h_2_p) <= 180 {
h_p_bar = (h_1_p + h_2_p) / 2
} else if fabs(h_1_p - h_2_p) > 180 && (h_1_p + h_2_p) < 360 {
} else if abs(h_1_p - h_2_p) > 180 && (h_1_p + h_2_p) < 360 {
h_p_bar = (h_1_p + h_2_p + 360) / 2
} else if fabs(h_1_p - h_2_p) > 180 && (h_1_p + h_2_p) >= 360 {
} else if abs(h_1_p - h_2_p) > 180 && (h_1_p + h_2_p) >= 360 {
h_p_bar = (h_1_p + h_2_p - 360) / 2
}

@@ -27,7 +27,7 @@ extension UIImage {
let inputExtent = CIVector(x: extent.origin.x, y: extent.origin.y, z: extent.size.width, w: extent.size.height)

guard
let filter = CIFilter(name: "CIAreaAverage", withInputParameters: [kCIInputImageKey: inputImage, kCIInputExtentKey: inputExtent]),
let filter = CIFilter(name: "CIAreaAverage", parameters: [kCIInputImageKey: inputImage, kCIInputExtentKey: inputExtent]),
let outputImage = filter.outputImage
else {
return nil
@@ -38,7 +38,7 @@ extension UIImage {
assert(outputExtent.size.width == 1 && outputExtent.size.height == 1)

// Render to bitmap.
context.render(outputImage, toBitmap: &bitmap, rowBytes: 4, bounds: CGRect(x: 0, y: 0, width: 1, height: 1), format: kCIFormatRGBA8, colorSpace: CGColorSpaceCreateDeviceRGB())
context.render(outputImage, toBitmap: &bitmap, rowBytes: 4, bounds: CGRect(x: 0, y: 0, width: 1, height: 1), format: CIFormat.RGBA8, colorSpace: CGColorSpaceCreateDeviceRGB())

// Compute result.
let result = UIColor(red: CGFloat(bitmap[0]) / 255.0, green: CGFloat(bitmap[1]) / 255.0, blue: CGFloat(bitmap[2]) / 255.0, alpha: CGFloat(bitmap[3]) / 255.0)
@@ -50,7 +50,7 @@ extension UIView {
let emitter = CAEmitterLayer()

emitter.emitterPosition = CGPoint(x: self.frame.size.width / 2.0, y: 0)
emitter.emitterShape = kCAEmitterLayerLine
emitter.emitterShape = CAEmitterLayerEmitterShape.line
emitter.emitterSize = CGSize(width: self.frame.size.width, height: 1)

let confettis: [(color: UIColor, image: UIImage)] = [
@@ -9,7 +9,7 @@
import UIKit

extension UIViewController {
func showAlert(_ title: String?, message: String?, style: UIAlertControllerStyle = .alert, completion: (() -> Void)? = nil) {
func showAlert(_ title: String?, message: String?, style: UIAlertController.Style = .alert, completion: (() -> Void)? = nil) {
let alert = UIAlertController(title: title, message: message, preferredStyle: style)
let okButton = UIAlertAction(title: "OK", style: .default) { _ in
completion?()
@@ -14,7 +14,7 @@ class AppNavigationController: UINavigationController {
private var themedStatusBarStyle: UIStatusBarStyle?

private var rootViewController: UIViewController? {
return self.childViewControllers.first
return self.children.first
}

override var preferredStatusBarStyle: UIStatusBarStyle {
@@ -70,11 +70,11 @@ extension AppNavigationController: Themeable {
navigationBar.barTintColor = theme.backgroundColor
navigationBar.tintColor = theme.highlightColor
navigationBar.titleTextAttributes = [
NSAttributedStringKey.foregroundColor: theme.navigationTitleColor
NSAttributedString.Key.foregroundColor: theme.navigationTitleColor
]
if #available(iOS 11.0, *) {
navigationBar.largeTitleTextAttributes = [
NSAttributedStringKey.foregroundColor: theme.navigationTitleColor
NSAttributedString.Key.foregroundColor: theme.navigationTitleColor
]
}
self.separatorView.backgroundColor = theme.separatorColor
@@ -68,13 +68,13 @@ class MiniPlayerViewController: PlayerContainerViewController, UIGestureRecogniz
// MARK: Notification handlers
@objc private func onBookPlay() {
self.playPauseButton.setImage(self.pauseImage, for: UIControlState())
self.playPauseButton.setImage(self.pauseImage, for: UIControl.State())
self.playPauseButton.accessibilityLabel = "Pause"
self.playPauseButton.accessibilityHint = "Tap to Pause"
}

@objc private func onBookPause() {
self.playPauseButton.setImage(self.playImage, for: UIControlState())
self.playPauseButton.setImage(self.playImage, for: UIControl.State())
self.playPauseButton.accessibilityLabel = "Play"
self.playPauseButton.accessibilityHint = "Tap to Play"
}
@@ -31,7 +31,7 @@ class ImportManager {
private func setupTimer() {
self.timer?.invalidate()
self.timer = Timer(timeInterval: self.timeout, target: self, selector: #selector(self.createOperation), userInfo: nil, repeats: false)
RunLoop.main.add(self.timer!, forMode: RunLoopMode.commonModes)
RunLoop.main.add(self.timer!, forMode: RunLoop.Mode.common)
}

@objc private func createOperation() {
@@ -345,7 +345,7 @@ extension ItemListViewController {
return
}

guard let index = (self.items.index { (item) -> Bool in
guard let index = (self.items.firstIndex { (item) -> Bool in
if let book = item as? Book {
return book.fileURL == fileURL
}
@@ -497,7 +497,7 @@ extension ItemListViewController: UITableViewDelegate {
return indexPath.sectionValue == .data
}

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
return .none
}

@@ -41,7 +41,7 @@ class RootViewController: UIViewController, UIGestureRecognizerDelegate {
}
} else if
let navigationVC = segue.destination as? UINavigationController,
let libraryVC = navigationVC.childViewControllers.first as? LibraryViewController {
let libraryVC = navigationVC.children.first as? LibraryViewController {
self.libraryViewController = libraryVC
}
}
@@ -44,7 +44,7 @@ final class ThemeManager: ThemeProvider {
currentTheme.useDarkVariant = self.useDarkVariant
self.theme = SubscribableValue<Theme>(value: currentTheme)

NotificationCenter.default.addObserver(self, selector: #selector(self.brightnessChanged(_:)), name: .UIScreenBrightnessDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.brightnessChanged(_:)), name: UIScreen.brightnessDidChangeNotification, object: nil)
}

@objc private func brightnessChanged(_ notification: Notification) {
@@ -114,7 +114,7 @@ class ItemProgress: UIView {

mask.frame = bounds
mask.contents = #imageLiteral(resourceName: "completionIndicatorDone").cgImage
mask.contentsGravity = kCAGravityResizeAspect
mask.contentsGravity = CALayerContentsGravity.resizeAspect

self.completionCheckmark.frame = bounds
self.completionCheckmark.mask = mask
@@ -15,7 +15,7 @@ class BookActivityItemProvider: UIActivityItemProvider {
super.init(placeholderItem: book)
}

override func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivityType?) -> Any? {
override func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
let tempDir = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let tempUrl = tempDir.appendingPathComponent(self.book.filename)

@@ -74,7 +74,7 @@ public class Library: NSManagedObject {
func getNextItem(after item: LibraryItem) -> LibraryItem? {
guard let items = self.items?.array as? [LibraryItem] else { return nil }

guard let indexFound = items.index(of: item) else { return nil }
guard let indexFound = items.firstIndex(of: item) else { return nil }

for (index, item) in items.enumerated() {
guard index > indexFound,
Oops, something went wrong.

0 comments on commit cf90a2d

Please sign in to comment.
You can’t perform that action at this time.