UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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?

4      

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.

4      

@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?

4      

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.

4      

@Hatsushira Thanks I will use the function you mentioned.

4      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out 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.