FREE TRIAL: Accelerate your app development career with 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?

   

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 Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Get started

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.