DEV Community

Cover image for Day 9: Making a swift macOS password manager for people who hate the cloud
Sean Walker
Sean Walker

Posted on • Originally published at streaking.app

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

<- For Day 8 go here

📅 Jan 9th 2019
🚀 21 days until launch
🔥 9 day streak
🤑 0 usd
📈 0 customers
⌚️ 7.55 hours spent
💻 18 files changed, 987 insertions(+), 171 deletions(-)
🏁 Today's goals: Edit/delete existing passwords

11:35 PM

Definitely the most focused day since I only had 30 minutes before midnight, just going to get the delete working from the menu, definitely have to pick up the pace tomorrow though.

11:49 PM

I've done it, I've cracked the code. Luckily functional programming translates into most other languages pretty well, even the statically typed ones (I'm coming from clojure). What I needed to do was map the delete menu item to a function in AppDelegate.swift then do the old first responder trick and finally copy and paste that function definition to PasswordListViewController.swift.

From there it was just figuring out how to get multiple rows out of the array of Row objects and viola, sqlite.swift could take over with a .filter([].contains(id)). Here's how it looks in code

@IBAction func deleteLogin(_ sender: NSMenuItem) {
    do {
        let indices = tableView.selectedRowIndexes
        let ids = indices.compactMap { (logins?.count ?? -1 > $0) ? logins?[$0][login.id] : nil}
        let lg = login.table.filter(ids.contains(login.id))
        if try db.run(lg.delete()) > 0 {
            logins = Array(try! db.prepare(login.table))
            tableView.reloadData()
        } else {
            print("login not found")
        }
    } catch {
        print("delete failed: \(error)")
    }
}

⌚️ ~8 hours spent. Tomorrow will be a much more productive day. I'm sure of it

Top comments (0)