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

Language newb, separating UI from persistent data

Forums > Swift

Possibly this could be categorized under MVC (MVVC?), but more likely under, That's Not How We Do It With Swift.

Problem Setup

I'm writing a custom Twitter client application; I've actually already done this in Java, and am using it as an opportunity to try applying what I'm learning in the Hacking with macOS book.

I've imported the Swifter framework to handle the Twitter API interactions.

Now, in my previous implementation, I had some objects that represented the API client, the user's saved credentials (so you don't have to log in every time you quit and relaunch the app), and the most recently fetched items on the timeline. Those sat out in a global space and the UI checked that global space for what to display.

The Question

I'm having a really hard time visualising how to structure this in a Swift project. All the examples I've worked through seem to embed the state right into the view classes, so there's not really one place to find all the state management. Further, there's the problem of deciding what to display: if you're not logged in, there's really nothing to show except a login button, but if you are logged in, then you should get a timeline window. Where should that logic reside? And should those be two distinct Views (I would assume so) or is it more Swifty to maybe use SwiftUI and just handle this in the var body: some View {...} code block?

2      

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.