Skip to content

Commit

Permalink
Migrate to Swift 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tallerthenyou committed Sep 13, 2017
1 parent b6b285f commit c26b292
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 65 deletions.
8 changes: 5 additions & 3 deletions MiniKeePass.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@
TargetAttributes = {
689DFFD413A4273F005EBD36 = {
DevelopmentTeam = G9ZT7943FZ;
LastSwiftMigration = 0830;
LastSwiftMigration = 0900;
SystemCapabilities = {
com.apple.iCloud = {
enabled = 0;
Expand Down Expand Up @@ -1259,7 +1259,8 @@
PROVISIONING_PROFILE_SPECIFIER = "Flush Software Development: *";
SWIFT_OBJC_BRIDGING_HEADER = "MiniKeePass/MiniKeePass-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -1281,7 +1282,8 @@
PROVISIONING_PROFILE = "5443260a-ff69-4503-8b4b-2b598dc5db88";
PROVISIONING_PROFILE_SPECIFIER = "Flush Software Development: *";
SWIFT_OBJC_BRIDGING_HEADER = "MiniKeePass/MiniKeePass-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
6 changes: 3 additions & 3 deletions MiniKeePass/Custom Field View/CustomFieldViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class CustomFieldViewController: UITableViewController {
@IBOutlet weak var valueTextField: UITextField!
@IBOutlet weak var inMemoryProtectionSwitch: UISwitch!

var stringField: StringField?
@objc var stringField: StringField?

var donePressed: ((_ customFieldViewController: CustomFieldViewController) -> Void)?
var cancelPressed: ((_ customFieldViewController: CustomFieldViewController) -> Void)?
@objc var donePressed: ((_ customFieldViewController: CustomFieldViewController) -> Void)?
@objc var cancelPressed: ((_ customFieldViewController: CustomFieldViewController) -> Void)?

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
4 changes: 2 additions & 2 deletions MiniKeePass/DatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ - (void)openDatabaseWithPasswordEntryViewController:(PasswordEntryViewController
NSString *path = [documentsDirectory stringByAppendingPathComponent:self.selectedFilename];

// Get the password
NSString *password = [passwordEntryViewController getPassword];
NSString *password = passwordEntryViewController.password;
if ([password isEqualToString:@""]) {
password = nil;
}

// Get the keyfile
NSString *keyFile = [passwordEntryViewController getKeyFile];
NSString *keyFile = passwordEntryViewController.keyFile;
NSString *keyFilePath = nil;
if (keyFile != nil) {
NSString *documentsDirectory = [AppDelegate documentsDirectory];
Expand Down
12 changes: 6 additions & 6 deletions MiniKeePass/Group View/GroupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class GroupViewController: UITableViewController {

// MARK: - Actions

func settingsPressed(sender: UIBarButtonItem) {
@objc func settingsPressed(sender: UIBarButtonItem) {
let storyboard = UIStoryboard(name: "Settings", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() else {
return
Expand All @@ -363,7 +363,7 @@ class GroupViewController: UITableViewController {
present(viewController, animated: true, completion: nil)
}

func actionPressed(sender: UIBarButtonItem) {
@objc func actionPressed(sender: UIBarButtonItem) {
// Get the URL of the database
guard let appDelegate = AppDelegate.getDelegate() else {
return
Expand All @@ -381,7 +381,7 @@ class GroupViewController: UITableViewController {
}
}

func addPressed(sender: UIBarButtonItem) {
@objc func addPressed(sender: UIBarButtonItem) {
let alertController = UIAlertController(title: NSLocalizedString("Add", comment: ""), message: nil, preferredStyle: .alert)

// Add an action to add a new group
Expand Down Expand Up @@ -489,13 +489,13 @@ class GroupViewController: UITableViewController {
navigationController?.pushViewController(viewController, animated: true)
}

func deletePressed(sender: UIBarButtonItem) {
@objc func deletePressed(sender: UIBarButtonItem) {
if let indexPaths = tableView.indexPathsForSelectedRows {
deleteItems(indexPaths: indexPaths)
}
}

func movePressed(sender: UIBarButtonItem) {
@objc func movePressed(sender: UIBarButtonItem) {
guard let indexPaths = tableView.indexPathsForSelectedRows else {
// Nothing selected. Shouldn't have been possible to press "Move"
return;
Expand Down Expand Up @@ -545,7 +545,7 @@ class GroupViewController: UITableViewController {
present(navigationController, animated: true, completion: nil)
}

func renamePressed(sender: UIBarButtonItem) {
@objc func renamePressed(sender: UIBarButtonItem) {
guard let indexPath = tableView.indexPathForSelectedRow else {
// Nothing selected. This shoudn't have been called
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class ImageSelectorViewController: UICollectionViewController {
private let reuseIdentifier = "ImageCell"
private var images: [UIImage] = []

var selectedImage = -1
@objc var selectedImage = -1

var imageSelected: ((_ imageSelectorViewController: ImageSelectorViewController, _ selectedImage: Int) -> Void)?
@objc var imageSelected: ((_ imageSelectorViewController: ImageSelectorViewController, _ selectedImage: Int) -> Void)?

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
26 changes: 14 additions & 12 deletions MiniKeePass/Password Entry View/KeyFileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import UIKit

class KeyFileViewController: UITableViewController {
var keyFiles: [String]!
var selectedIndex: Int!
var selectedKeyIndex: Int?

var keyFileSelected: ((_ selectedIndex: Int) -> Void)?
var keyFileSelected: ((_ selectedIndex: Int?) -> Void)?

// MARK: - Table view data source

Expand All @@ -35,31 +35,33 @@ class KeyFileViewController: UITableViewController {
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let idx = indexPath.row - 1

let cell = tableView.dequeueReusableCell(withIdentifier: "KeyFileCell", for: indexPath)
if (idx == -1) {
if (indexPath.row == 0) {
cell.textLabel?.text = NSLocalizedString("None", comment: "")
cell.accessoryType = (selectedKeyIndex == nil ? .checkmark : .none)
} else {
cell.textLabel?.text = keyFiles[idx]
let keyIndex = indexPath.row - 1
cell.textLabel?.text = keyFiles[keyIndex]
cell.accessoryType = (keyIndex == selectedKeyIndex ? .checkmark : .none)
}
cell.accessoryType = idx == selectedIndex ? .checkmark : .none

return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let idx = indexPath.row - 1
if (idx != selectedIndex) {
let oldCell = tableView.cellForRow(at: IndexPath(row: selectedIndex + 1, section: 0))
let keyIndex = indexPath.row > 0 ? indexPath.row - 1 : nil
let oldIndexPath = IndexPath(row: (selectedKeyIndex ?? -1) + 1, section: 0)

if (indexPath != oldIndexPath) {
let oldCell = tableView.cellForRow(at: oldIndexPath)
oldCell!.accessoryType = .none

let cell = tableView.cellForRow(at: indexPath)
cell!.accessoryType = .checkmark

selectedIndex = idx
selectedKeyIndex = keyIndex

keyFileSelected?(selectedIndex)
keyFileSelected?(selectedKeyIndex)
}

tableView.deselectRow(at: indexPath, animated: true)
Expand Down
61 changes: 28 additions & 33 deletions MiniKeePass/Password Entry View/PasswordEntryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,46 @@ class PasswordEntryViewController: UITableViewController, UITextFieldDelegate {
@IBOutlet weak var showImageView: UIImageView!
@IBOutlet weak var keyFileLabel: UILabel!

var filename: String!
@objc var filename: String!

var keyFiles: [String]!
fileprivate var selectedKeyFileIndex: Int! = -1
@objc var keyFiles: [String]!
fileprivate var selectedKeyFileIndex: Int? = nil {
didSet {
if let selectedKeyFileIndex = selectedKeyFileIndex {
keyFileLabel.text = keyFiles[selectedKeyFileIndex]
} else {
keyFileLabel.text = NSLocalizedString("None", comment: "")
}
}
}

@objc var keyFile: String? {
guard let selectedKeyFileIndex = selectedKeyFileIndex else {
return nil
}

return keyFiles[selectedKeyFileIndex]
}

@objc var password: String! {
return passwordTextField.text
}

var donePressed: ((PasswordEntryViewController) -> Void)?
var cancelPressed: ((PasswordEntryViewController) -> Void)?
@objc var donePressed: ((PasswordEntryViewController) -> Void)?
@objc var cancelPressed: ((PasswordEntryViewController) -> Void)?

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

if (keyFileLabel.text == "") {
let keyFile = ((filename as NSString).deletingPathExtension as NSString).appendingPathExtension("key")
let idx = keyFiles.index(of: keyFile!)
setSelectedKeyFile(idx)
selectedKeyFileIndex = idx
}

passwordTextField.becomeFirstResponder()
}

func getPassword() -> String! {
return passwordTextField.text
}

func getKeyFile() -> String! {
if (selectedKeyFileIndex == -1) {
return nil
}
return keyFiles[selectedKeyFileIndex]
}

func setSelectedKeyFile(_ selectedIndex: Int!) -> Void {
if (selectedIndex == nil) {
selectedKeyFileIndex = -1
} else {
selectedKeyFileIndex = selectedIndex
}

if (selectedKeyFileIndex == -1) {
keyFileLabel.text = NSLocalizedString("None", comment: "")
} else {
keyFileLabel.text = keyFiles[selectedKeyFileIndex]
}
}

// MARK: - UITextFieldDelegate

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
Expand All @@ -88,9 +83,9 @@ class PasswordEntryViewController: UITableViewController, UITextFieldDelegate {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let keyFileViewController = segue.destination as! KeyFileViewController
keyFileViewController.keyFiles = keyFiles
keyFileViewController.selectedIndex = selectedKeyFileIndex
keyFileViewController.selectedKeyIndex = selectedKeyFileIndex
keyFileViewController.keyFileSelected = { (selectedIndex) in
self.setSelectedKeyFile(selectedIndex)
self.selectedKeyFileIndex = selectedIndex

keyFileViewController.navigationController?.popViewController(animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class PasswordGeneratorViewController: UITableViewController, UIPickerViewDataSo
fileprivate var length: Int = 0
fileprivate var charSets: Int = 10

var donePressed: ((PasswordGeneratorViewController, _ password: String) -> Void)?
var cancelPressed: ((PasswordGeneratorViewController) -> Void)?
@objc var donePressed: ((PasswordGeneratorViewController, _ password: String) -> Void)?
@objc var cancelPressed: ((PasswordGeneratorViewController) -> Void)?

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
4 changes: 2 additions & 2 deletions MiniKeePass/Web Browser View/WebBrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class WebBrowserViewController: UIViewController, WKNavigationDelegate {

fileprivate var webView: WKWebView!

var url: URL?
var entry: KdbEntry?
@objc var url: URL?
@objc var entry: KdbEntry?

override func loadView() {
super.loadView()
Expand Down

0 comments on commit c26b292

Please sign in to comment.