@sean
🔥 40 day streak
500 words

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

<- For Day 3 go here

I got super sidetracked today and there's an hour left until midnight, BUT I'm determined to keep the streak alive! So this is what I did today, I moved the tableview over and I decided to completely rip 1password off with it's weird ios/macos hybrid app. So here's what the table view looks like, it's one column, as the late great steve jobs has let us know is really the only way to make tableviews

So that actually looks really fricken good, only took a few constraints in storyboard to make it too. I'm actually starting to like macos development, I'm starting to see how backwards CSS is. In short. I'm a fan now compared to a few days ago, or maybe that's just the stockholm syndrome working it's swedish magic? Anyway, so that looks good, unfortunately, still no passwords in there, so here's what I wanted to do Cmd+N or File->New to make a new password with a new view to the right of it. Boy, I didn't know what I was in for. I start to click around my storyboard and voila

you can actually select the little fake menu there, and you can select File->New, so my next thought was let me drag this to the view controller, but no that doesn't work. I'm starting to get envious of web developers again, and of course I immediately google up a solution. You have to control + drag your mouse 🐁 TWO TIMES. First from New to the AppDelegate.swift file like so

In this gif I had already done it and wired it to addNewLogin, but there it is, you make up a func and you're almost home. Then from there you control+drag from New to that little orange box next to the two blue boxes and you select the name of the function YOU JUST MADE. Now the third and final step is to... and I 💩 you not, COPY AND PASTE the function definition from AppDelegate.swift to the view controller DOT swift file of your choice.

At this point, I'm so many WTFs deep and so pressed for time that I'm just happy the thing is firing at all. But I still have an hour and both of my daily goals are about to be met (daily blog and daily progress toward this password manager), so I press on. I get as far as showing the "add password" view controller and then that's it, time's up. So here's what I wound up with in terms of code:

    @IBAction func addNewLogin(_ sender: NSMenuItem) {

        let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: Bundle.main)
        let viewController = storyboard.instantiateController(withIdentifier: "AddLoginViewController") as! NSViewController

        for sView in self.containerView.subviews {
            sView.removeFromSuperview()
        }

        viewController.view.frame = containerView.bounds
        containerView.addSubview(viewController.view)
    }

Oh! That's hot... that's hot. Barely any code today!

Kids, don't drink and program. Day 5 coming soon (as in tomorrow)