fix(ios): most of the new Swift 5 deprecations

This commit is contained in:
jahorton 2019-10-28 12:15:38 +07:00
parent 854fc6d3ba
commit bf39c854ed
5 changed files with 13 additions and 11 deletions

View file

@ -38,7 +38,7 @@ class KeyboardSwitcherViewController: UITableViewController, UIAlertViewDelegate
}
public func scroll(toSelectedKeyboard animated: Bool) {
let index = userKeyboards.index { kb in
let index = userKeyboards.firstIndex { kb in
return Manager.shared.currentKeyboardID == kb.fullID
}

View file

@ -271,7 +271,7 @@ class LexicalModelPickerViewController: UITableViewController, UIAlertViewDelega
}
private func scroll(toSelectedLexicalModel animated: Bool) {
let index = userLexicalModels.index { lm in
let index = userLexicalModels.firstIndex { lm in
return Manager.shared.currentLexicalModelID == lm.fullID
}

View file

@ -331,7 +331,7 @@ public class Manager: NSObject, UIGestureRecognizerDelegate {
var userKeyboards = userDefaults.userKeyboards ?? []
// Update keyboard if it exists
if let index = userKeyboards.index(where: { $0.fullID == keyboard.fullID }) {
if let index = userKeyboards.firstIndex(where: { $0.fullID == keyboard.fullID }) {
userKeyboards[index] = keyboard
} else {
userKeyboards.append(keyboard)
@ -396,7 +396,7 @@ public class Manager: NSObject, UIGestureRecognizerDelegate {
var userLexicalModels = userDefaults.userLexicalModels ?? []
// Update lexical model if it exists
if let index = userLexicalModels.index(where: { $0.fullID == lexicalModel.fullID }) {
if let index = userLexicalModels.firstIndex(where: { $0.fullID == lexicalModel.fullID }) {
userLexicalModels[index] = lexicalModel
} else {
userLexicalModels.append(lexicalModel)
@ -412,7 +412,7 @@ public class Manager: NSObject, UIGestureRecognizerDelegate {
/// - Returns: The keyboard exists and was removed
public func removeKeyboard(withFullID fullID: FullKeyboardID) -> Bool {
// Remove keyboard from the list if it exists
let index = Storage.active.userDefaults.userKeyboards?.index { $0.fullID == fullID }
let index = Storage.active.userDefaults.userKeyboards?.firstIndex { $0.fullID == fullID }
if let index = index {
return removeKeyboard(at: index)
}
@ -473,7 +473,7 @@ public class Manager: NSObject, UIGestureRecognizerDelegate {
/// - Returns: The lexical model exists and was removed
public func removeLexicalModel(withFullID fullID: FullLexicalModelID) -> Bool {
// Remove lexical model from the list if it exists
let index = Storage.active.userDefaults.userLexicalModels?.index { $0.fullID == fullID }
let index = Storage.active.userDefaults.userLexicalModels?.firstIndex { $0.fullID == fullID }
if let index = index {
return removeLexicalModel(at: index)
}
@ -555,7 +555,7 @@ public class Manager: NSObject, UIGestureRecognizerDelegate {
/// - Returns: Index of the newly selected keyboard.
public func switchToNextKeyboard() -> Int? {
guard let userKeyboards = Storage.active.userDefaults.userKeyboards,
let index = userKeyboards.index(where: { self.currentKeyboardID == $0.fullID })
let index = userKeyboards.firstIndex(where: { self.currentKeyboardID == $0.fullID })
else {
return nil
}

View file

@ -336,7 +336,7 @@ class LanguageSettingsViewController: UITableViewController {
return nil
}
if let index = globalUserKeyboards.index(where: { $0.fullID == matchingFullID }) {
if let index = globalUserKeyboards.firstIndex(where: { $0.fullID == matchingFullID }) {
guard index < globalUserKeyboards.count else {
return nil
}
@ -354,7 +354,7 @@ class LanguageSettingsViewController: UITableViewController {
let userData = Storage.active.userDefaults
// If user defaults for keyboards list does not exist, do nothing.
guard var globalUserKeyboards = userData.userKeyboards else {
guard let globalUserKeyboards = userData.userKeyboards else {
log.error("no keyboards in the global keyboards list!")
return
}
@ -395,7 +395,7 @@ class LanguageSettingsViewController: UITableViewController {
let userData = Storage.active.userDefaults
if let globalUserLexicalModels = userData.userLexicalModels {
if let index = globalUserLexicalModels.index(where: { $0.fullID == matchingFullID }) {
if let index = globalUserLexicalModels.firstIndex(where: { $0.fullID == matchingFullID }) {
guard index < globalUserLexicalModels.count else {
return
}

View file

@ -61,7 +61,9 @@ class SetUpViewController: UIViewController, UIWebViewDelegate {
// Yes, .php.html. That's how `wget` is set to retrieve it, since Safari won't recognize the contents
// without the .html ending, it seems.
let filePath = offlineHelpBundle.path(forResource: "installing-system-keyboard.php", ofType: "html", inDirectory: nil)
let filePath = offlineHelpBundle.path(forResource: "installing-system-keyboard.php",
ofType: "html",
inDirectory: nil)
webView.loadRequest(URLRequest(url: URL.init(fileURLWithPath: filePath!)))
}