TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

One window/view controller for both add and update SQLite table?

Forums > macOS

Environment is macOS Xcode 11 and interface builder. What would be the best approach to add update and add function window for an SQLite table? Could I use a single Window/View Controller for both? I would like to have a single window for both add and update? To aid in this I could set a global variable to know where the window was activated from? I am looking for general direction as if I could use one Window/View Controller for both the add and update window. My thinking was both add and update would have the same fields so to make it easy on setup and maintenance one window would be better than two.

Any thoughts on this?


I usually tend to do the same. But it really depends on the use case I have. F.e. if you really have the same fields for adding and editing you can go for it. You just have to adapt your controls (for adding no delete necessery etc.). On the other hand, if your record has a lot of fields and you don't ususally fill them all in when adding a record I wouldn't use the same view and create a new one with just the fields to fill out.


@Hatsushira thanks for the reply. I think in my case I will use one window for both. However, question about adaptive controls I would need. Is there a way the window controller/view can tell where it came from as add or update or would I have to create a global variable to indicate add or update?


You could use func performSegue(withIdentifier: String, sender: Any?) in the view controller which calls it. In this function you could set the specific controls visible/invisible.


@Hatsushira Thanks I will use the function you mentioned.


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.