Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 5 for TEA #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Recordings-TEA/Recordings.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,18 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0930;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "";
TargetAttributes = {
C90DE10C20830C580054A4BA = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
TestTargetID = C9EB56BC1EAE33C1000EC5F4;
};
C9EB56BC1EAE33C1000EC5F4 = {
CreatedOnToolsVersion = 8.3.2;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
Expand All @@ -269,6 +270,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -377,7 +379,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.cocoawithlove.RecordingsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Recordings.app/Recordings";
};
Expand All @@ -400,7 +402,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.cocoawithlove.RecordingsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Recordings.app/Recordings";
};
Expand All @@ -410,6 +412,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -469,6 +472,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -528,7 +532,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "io.objc.Recordings-TEA";
PRODUCT_NAME = Recordings;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -543,7 +547,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "io.objc.Recordings-TEA";
PRODUCT_NAME = Recordings;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Recordings-TEA/Recordings/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
view: { state in state.viewController },
subscriptions: { state in state.subscriptions })

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = driver.viewController
window?.makeKeyAndVisible()
Expand Down
7 changes: 6 additions & 1 deletion Recordings-TEA/Recordings/Player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Player: NSObject, AVAudioPlayerDelegate {

init?(url: URL, update: ((TimeInterval?, _ isPlaying: Bool) -> ())? = nil) {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.playAndRecord)))
try AVAudioSession.sharedInstance().setActive(true)
} catch {
return nil
Expand Down Expand Up @@ -71,3 +71,8 @@ class Player: NSObject, AVAudioPlayerDelegate {
timer?.invalidate()
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String {
return input.rawValue
}
7 changes: 6 additions & 1 deletion Recordings-TEA/Recordings/Recorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class Recorder: NSObject, AVAudioRecorderDelegate {
super.init()

do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.playAndRecord)))
try AVAudioSession.sharedInstance().setActive(true)
AVAudioSession.sharedInstance().requestRecordPermission() { allowed in
if allowed {
Expand Down Expand Up @@ -58,3 +58,8 @@ final class Recorder: NSObject, AVAudioRecorderDelegate {
}
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String {
return input.rawValue
}
30 changes: 15 additions & 15 deletions Recordings-TEA/Recordings/VirtualViews+Rendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class NCDelegate: NSObject, UINavigationControllerDelegate {
self.popDetail = popDetail
}

func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if operation == .pop {
if (navigationController.splitViewController?.delegate as? SplitViewControllerDelegate)?.detailViewController === fromVC {
popDetail()
Expand Down Expand Up @@ -67,7 +67,7 @@ class TableViewBacking<A>: NSObject, UITableViewDataSource, UITableViewDelegate
return cell
}

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete, let action = cells[indexPath.row].onDelete {
callback?(action)
}
Expand Down Expand Up @@ -299,8 +299,8 @@ struct Renderer<Message> {
}

func childViewController(for existing: UIView) -> UIViewController? {
guard let i = container.childViewControllers.index(where: { $0.view == existing }) else { return nil }
return container.childViewControllers[i]
guard let i = container.children.firstIndex(where: { $0.view == existing }) else { return nil }
return container.children[i]
}

mutating func render(view: View<Message>) -> UIView {
Expand Down Expand Up @@ -347,13 +347,13 @@ struct Renderer<Message> {
}
return v
case let ._activityIndicator(indicator):
let result = UIActivityIndicatorView(activityIndicatorStyle: indicator.style)
let result = UIActivityIndicatorView(style: indicator.style)
result.startAnimating()
return result
case ._childViewController(let vc):
var result = UIViewController()
strongReferences.append(vc.render(callback: callback, change: &result))
container.addChildViewController(result)
container.addChild(result)
addedChildViewControllers.append(result)
return result.view
case ._customLayout(let views):
Expand All @@ -370,10 +370,10 @@ struct Renderer<Message> {
}

mutating func removeChildViewController(for view: UIView) {
guard let i = container.childViewControllers.index(where: { $0.view == view }) else { return }
guard let i = container.children.firstIndex(where: { $0.view == view }) else { return }

let child = container.childViewControllers[i]
child.willMove(toParentViewController: nil)
let child = container.children[i]
child.willMove(toParent: nil)
removedChildViewControllers.append(child)
}

Expand Down Expand Up @@ -415,7 +415,7 @@ struct Renderer<Message> {
removeChildViewController(for: existing)
return render(view: view)
}
a.activityIndicatorViewStyle = indicator.style
a.style = indicator.style
return a
case let ._textField(textField):
guard let result = existing as? UITextField else {
Expand Down Expand Up @@ -453,9 +453,9 @@ struct Renderer<Message> {
var resultVC = existingVC
strongReferences.append(vc.render(callback: callback, change: &resultVC))
if resultVC != existingVC {
existingVC.willMove(toParentViewController: nil)
existingVC.willMove(toParent: nil)
removedChildViewControllers.append(existingVC)
container.addChildViewController(resultVC)
container.addChild(resultVC)
addedChildViewControllers.append(resultVC)
}
return resultVC.view
Expand Down Expand Up @@ -522,7 +522,7 @@ extension SplitViewController {
let n = UINavigationController()
n.navigationBar.barTintColor = .blueTint
n.navigationBar.tintColor = .orangeTint
n.navigationBar.titleTextAttributes = [NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.white]
n.navigationBar.titleTextAttributes = [NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.white]
return n
}

Expand Down Expand Up @@ -624,10 +624,10 @@ extension ViewController {
])
}
for removed in r.removedChildViewControllers {
removed.removeFromParentViewController()
removed.removeFromParent()
}
for added in r.addedChildViewControllers {
added.didMove(toParentViewController: change)
added.didMove(toParent: change)
}
return r.strongReferences
case .splitViewController(let newSVC, let modal):
Expand Down
25 changes: 13 additions & 12 deletions Recordings-TEA/Recordings/VirtualViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ struct TextField<Message> {

struct StackView<Message> {
let views: [View<Message>]
let axis: UILayoutConstraintAxis
let distribution: UIStackViewDistribution
let axis: NSLayoutConstraint.Axis
let distribution: UIStackView.Distribution
let backgroundColor: UIColor

init(views: [View<Message>], axis: UILayoutConstraintAxis = .vertical, distribution: UIStackViewDistribution = .equalCentering, backgroundColor: UIColor = .white) {
init(views: [View<Message>], axis: NSLayoutConstraint.Axis = .vertical, distribution: UIStackView.Distribution = .equalCentering, backgroundColor: UIColor = .white) {
self.views = views
self.axis = axis
self.distribution = distribution
Expand Down Expand Up @@ -65,16 +65,17 @@ struct TableViewCell<Message>: Hashable {
static func ==(lhs: TableViewCell<Message>, rhs: TableViewCell<Message>) -> Bool {
return lhs.identity == rhs.identity && lhs.text == rhs.text && lhs.accessory == rhs.accessory
}
var hashValue: Int {
return identity.hashValue
}

func hash(into hasher: inout Hasher) {
hasher.combine(identity)
}

let identity: AnyHashable
let text: String
let onSelect: Message?
let onDelete: Message?
let accessory: UITableViewCellAccessoryType
init(identity: AnyHashable, text: String, onSelect: Message?, accessory: UITableViewCellAccessoryType = .none, onDelete: Message?) {
let accessory: UITableViewCell.AccessoryType
init(identity: AnyHashable, text: String, onSelect: Message?, accessory: UITableViewCell.AccessoryType = .none, onDelete: Message?) {
self.identity = identity
self.text = text
self.accessory = accessory
Expand Down Expand Up @@ -105,7 +106,7 @@ struct Slider<Message> {
enum BarButtonItem<Message> {
case none
case builtin(UIBarButtonItem)
case system(UIBarButtonSystemItem, action: Message)
case system(UIBarButtonItem.SystemItem, action: Message)
case custom(text: String, action: Message)
case editButtonItem

Expand Down Expand Up @@ -140,7 +141,7 @@ struct Space {
}

struct ActivityIndicator {
let style: UIActivityIndicatorViewStyle
let style: UIActivityIndicatorView.Style
}

typealias Constraint = (_ child: UIView, _ parent: UIView) -> NSLayoutConstraint
Expand Down Expand Up @@ -221,7 +222,7 @@ extension View {
return ._imageView(ImageView(image: image))
}

static func stackView(views: [View<Message>], axis: UILayoutConstraintAxis = .vertical, distribution: UIStackViewDistribution = .equalCentering, backgroundColor: UIColor = .white) -> View {
static func stackView(views: [View<Message>], axis: NSLayoutConstraint.Axis = .vertical, distribution: UIStackView.Distribution = .equalCentering, backgroundColor: UIColor = .white) -> View {
return ._stackView(StackView(views: views, axis: axis, distribution: distribution, backgroundColor: backgroundColor))
}

Expand All @@ -237,7 +238,7 @@ extension View {
return ._space(Space(width: width, height: height))
}

static func activityIndicator(style: UIActivityIndicatorViewStyle = .white) -> View {
static func activityIndicator(style: UIActivityIndicatorView.Style = .white) -> View {
return ._activityIndicator(ActivityIndicator(style: style))
}
}
Expand Down