@sean
🔥 1 day streak
273 words

Day 3: Making a swift macOS password manager for people who hate the cloud

<- For Day 2 go here

My goal for today is to use the master password to unlock the app and show a blank screen where the list of passwords will be! Let's do it!

After quite a bit of searching around for various things like how to declare classes and then how to declare structs and then how to fill in a tableView and also how to switch the view controller in the window:

  • https://docs.swift.org/swift-book/LanguageGuide/Properties.html
  • https://stackoverflow.com/questions/44953830/swift-array-to-tableview-in-macos

I made some tangible progress!

Here's the code I wrote today:

    @IBAction func unlockButtonPressed(_ sender: NSButton) {
        let keychain = KeychainSwift()
        let masterPassword : String? = keychain.get("MasterPassword")

        if masterPassword == masterPasswordTextField.stringValue {
            let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: Bundle.main)
            let viewController = storyboard.instantiateController(withIdentifier: "PasswordListViewController") as! NSViewController
            self.view.window?.contentViewController = viewController
        }
    }

I also messed around with the password list view, but I think that's something I'll have to get to tomorrow, I am still working a full time rails job after all

import Cocoa
import KeychainSwift

struct Login {
    let id: Int64
    let username: String?
    let email: String?
    let key: String
}

class PasswordListViewController: NSViewController {
    let logins = [Login]()

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override var representedObject: Any? {
        didSet {

        }
    }

    func numberOfRows(in tableView: NSTableView) -> Int {
        return logins.count
    }

    func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
        return logins[row]
    }
}

Tune in tomorrow for Day 4 and actually adding passwords to that table view! There's going to be some rough and tumble SQL action.