From fb5036acf8fb7d603eb294e8dbd2ba252bb256f8 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 12 Oct 2017 14:40:15 -0700 Subject: [PATCH] Manually fixes Swift 4 migrator errors --- Cores/DeltaCore | 2 +- Cores/GBADeltaCore | 2 +- Cores/GBCDeltaCore | 2 +- Cores/SNESDeltaCore | 2 +- Delta.xcodeproj/project.pbxproj | 4 ++-- Delta/AppDelegate.swift | 2 +- Delta/Components/Popover Menu/PopoverMenuButton.swift | 4 ++-- Delta/Extensions/UILabel+FontSize.swift | 2 +- Delta/Pause Menu/Cheats/CheatTextView.swift | 11 +++++++---- Delta/Pause Menu/Cheats/EditCheatViewController.swift | 4 +++- .../ControllersSettingsViewController.swift | 4 ++-- Delta/Settings/SettingsViewController.swift | 4 ++-- 12 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Cores/DeltaCore b/Cores/DeltaCore index 97d29d5..1d74f64 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit 97d29d5eaaf4bd2310464ca6d4f91a85dcbf4e2e +Subproject commit 1d74f647aaeec653a3ab55d7c06a0b3c0dc95069 diff --git a/Cores/GBADeltaCore b/Cores/GBADeltaCore index 56401b9..588e118 160000 --- a/Cores/GBADeltaCore +++ b/Cores/GBADeltaCore @@ -1 +1 @@ -Subproject commit 56401b9649f8abe971e3a66be1a3bb2cd984a1a0 +Subproject commit 588e1183800e6d49950d833ddb6ac43e08e33424 diff --git a/Cores/GBCDeltaCore b/Cores/GBCDeltaCore index 4e678e7..2a735d6 160000 --- a/Cores/GBCDeltaCore +++ b/Cores/GBCDeltaCore @@ -1 +1 @@ -Subproject commit 4e678e7eac511d342aab86522eede9fdb7b29108 +Subproject commit 2a735d63e331e54935e2d9e997ab096631d3110f diff --git a/Cores/SNESDeltaCore b/Cores/SNESDeltaCore index 3946277..cde0fe0 160000 --- a/Cores/SNESDeltaCore +++ b/Cores/SNESDeltaCore @@ -1 +1 @@ -Subproject commit 394627784bd0643c26e0fc95feafa5c960786a7c +Subproject commit cde0fe0b39d9cfc97a0152116a0f0d607a6532cd diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index e5d16d4..7bf125b 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -1098,7 +1098,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Delta/Supporting Files/Delta-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 4.0; }; name = Debug; @@ -1120,7 +1120,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Delta/Supporting Files/Delta-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 4.0; }; name = Release; diff --git a/Delta/AppDelegate.swift b/Delta/AppDelegate.swift index 2b4d7a7..3c453c6 100644 --- a/Delta/AppDelegate.swift +++ b/Delta/AppDelegate.swift @@ -79,7 +79,7 @@ extension AppDelegate { self.window?.tintColor = UIColor.deltaPurple - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes[NSAttributedStringKey.foregroundColor] = UIColor.white + UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes[NSAttributedStringKey.foregroundColor.rawValue] = UIColor.white } } diff --git a/Delta/Components/Popover Menu/PopoverMenuButton.swift b/Delta/Components/Popover Menu/PopoverMenuButton.swift index f5bd940..6880f3b 100644 --- a/Delta/Components/Popover Menu/PopoverMenuButton.swift +++ b/Delta/Components/Popover Menu/PopoverMenuButton.swift @@ -10,7 +10,7 @@ import UIKit extension UINavigationBar { - fileprivate var defaultTitleTextAttributes: [String: Any]? { + fileprivate var defaultTitleTextAttributes: [NSAttributedStringKey: Any]? { if let textAttributes = self._defaultTitleTextAttributes { return textAttributes @@ -35,7 +35,7 @@ extension UINavigationBar return textAttributes } - fileprivate var _defaultTitleTextAttributes: [String: Any]? { + fileprivate var _defaultTitleTextAttributes: [NSAttributedStringKey: Any]? { guard self.titleTextAttributes == nil else { return self.titleTextAttributes } guard diff --git a/Delta/Extensions/UILabel+FontSize.swift b/Delta/Extensions/UILabel+FontSize.swift index 6390eb6..39695a5 100644 --- a/Delta/Extensions/UILabel+FontSize.swift +++ b/Delta/Extensions/UILabel+FontSize.swift @@ -18,7 +18,7 @@ internal extension UILabel context.minimumScaleFactor = self.minimumScaleFactor // Using self.attributedString returns incorrect calculations, so we create our own attributed string - let attributedString = NSAttributedString(string: text, attributes: [NSAttributedStringKey.font: self.font]) + let attributedString = NSAttributedString(string: text, attributes: [.font: self.font]) attributedString.boundingRect(with: self.bounds.size, options: [.usesLineFragmentOrigin, .usesFontLeading], context: context) let scaleFactor = context.actualScaleFactor diff --git a/Delta/Pause Menu/Cheats/CheatTextView.swift b/Delta/Pause Menu/Cheats/CheatTextView.swift index 177aea4..8c55458 100644 --- a/Delta/Pause Menu/Cheats/CheatTextView.swift +++ b/Delta/Pause Menu/Cheats/CheatTextView.swift @@ -13,7 +13,10 @@ import DeltaCore import Roxas -private let CheatPrefixAttribute = "prefix" +private extension NSAttributedStringKey +{ + static let cheatPrefix = NSAttributedStringKey("CheatPrefix") +} class CheatTextView: UITextView { @@ -44,7 +47,7 @@ extension CheatTextView if let format = self.cheatFormat, let font = self.font { - let characterWidth = ("A" as NSString).size(withAttributes: [NSAttributedStringKey.font: font]).width + let characterWidth = ("A" as NSString).size(withAttributes: [.font: font]).width let width = characterWidth * CGFloat(format.format.characters.count) self.textContainer.size = CGSize(width: width, height: 0) @@ -79,7 +82,7 @@ private extension CheatTextView if let prefixString = prefixString, prefixString.length > 0 { - attributedString.addAttribute(NSAttributedStringKey(rawValue: CheatPrefixAttribute), value: prefixString, range: NSRange(location: 0, length: 1)) + attributedString.addAttribute(.cheatPrefix, value: prefixString, range: NSRange(location: 0, length: 1)) } attributedFormat.append(attributedString) @@ -128,7 +131,7 @@ extension CheatTextView: NSLayoutManagerDelegate // The index the actual character maps to in the cheat format let characterIndex = charIndexes[i] % attributedFormat.length - if let prefix = attributedFormat.attributes(at: characterIndex, effectiveRange: nil)[CheatPrefixAttribute] as? String + if let prefix = attributedFormat.attributes(at: characterIndex, effectiveRange: nil)[.cheatPrefix] as? String { // If there is a prefix string, we insert the glyphs (and associated properties/character indexes) first let prefixCount = prefix.characters.count diff --git a/Delta/Pause Menu/Cheats/EditCheatViewController.swift b/Delta/Pause Menu/Cheats/EditCheatViewController.swift index 4ca62f7..dca907d 100644 --- a/Delta/Pause Menu/Cheats/EditCheatViewController.swift +++ b/Delta/Pause Menu/Cheats/EditCheatViewController.swift @@ -382,7 +382,9 @@ extension EditCheatViewController: UITextViewDelegate // We need to manually add back the attributes when manually modifying the underlying text storage // Otherwise, pasting text into an empty text view will result in the wrong font being used - let attributedString = NSAttributedString(string: sanitizedText, attributes: textView.typingAttributes) + let attributes = Dictionary(uniqueKeysWithValues: textView.typingAttributes.map { (key, value) in (NSAttributedStringKey(key), value) }) + + let attributedString = NSAttributedString(string: sanitizedText, attributes: attributes) textView.textStorage.replaceCharacters(in: range, with: attributedString) // We must add attributedString.length, not range.length, in case the attributed string's length differs diff --git a/Delta/Settings/Controllers/ControllersSettingsViewController.swift b/Delta/Settings/Controllers/ControllersSettingsViewController.swift index f65989c..103101d 100644 --- a/Delta/Settings/Controllers/ControllersSettingsViewController.swift +++ b/Delta/Settings/Controllers/ControllersSettingsViewController.swift @@ -174,7 +174,7 @@ private extension ControllersSettingsViewController private extension ControllersSettingsViewController { - @objc dynamic func externalGameControllerDidConnect(_ notification: Notification) + @objc func externalGameControllerDidConnect(_ notification: Notification) { guard let controller = notification.object as? GameController else { return } @@ -217,7 +217,7 @@ private extension ControllersSettingsViewController } } - @objc dynamic func externalGameControllerDidDisconnect(_ notification: Notification) + @objc func externalGameControllerDidDisconnect(_ notification: Notification) { guard let controller = notification.object as? GameController else { return } diff --git a/Delta/Settings/SettingsViewController.swift b/Delta/Settings/SettingsViewController.swift index 7bffae8..fc394a1 100644 --- a/Delta/Settings/SettingsViewController.swift +++ b/Delta/Settings/SettingsViewController.swift @@ -153,12 +153,12 @@ private extension SettingsViewController private extension SettingsViewController { - @objc dynamic func externalGameControllerDidConnect(_ notification: Notification) + @objc func externalGameControllerDidConnect(_ notification: Notification) { self.tableView.reloadSections(IndexSet(integer: Section.controllers.rawValue), with: .none) } - @objc dynamic func externalGameControllerDidDisconnect(_ notification: Notification) + @objc func externalGameControllerDidDisconnect(_ notification: Notification) { self.tableView.reloadSections(IndexSet(integer: Section.controllers.rawValue), with: .none) }