Day 4: Making a swift macOS password manager for people who hate the cloud
Tags: macos, swift, passwordmanager, cloud
Published: 2019-01-05 06:39:42

---
title: Day 4: Making a swift macOS password manager for people who hate the cloud
published: true
description: Watch as I make a password manager for macOS this month
tags: macos, swift, password manager, cloud
series: Making a swift MacOS password manager for people who hate the cloud
cover_image: https://thepracticaldev.s3.amazonaws.com/i/q6r73zbfbm3mpfs98bu5.jpg
canonical_url: https://streaking.app/posts/day-4-making-a-swift-macos-password-manager-for-people-who-hate-the-cloud-f7dfb3d9d8d5
---

[<- For Day 3 go here](https://dev.to/swlkr/day-3-making-a-swift-macos-password-manager-for-people-who-hate-the-cloud-5dii)

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

![](https://thepracticaldev.s3.amazonaws.com/i/0ikerm81e0uyyfqybnvk.png)

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

￼![](https://thepracticaldev.s3.amazonaws.com/i/zvxkh39reij8m4h24uuo.png)

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

￼![](https://thepracticaldev.s3.amazonaws.com/i/i7pm95jlgpn90sft8gmh.gif)

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:

```swift
    @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!

![](https://thepracticaldev.s3.amazonaws.com/i/mj4ivz2qf951vx0ovd03.gif)

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