NEW: Learn to build the incredible iOS 15 Weather app today! >>

Just can't make sense of SwiftUI; can someone have a look and point me in a sensible direction

Forums > SwiftUI

I thought it would just be so simple with SwiftUI, but I can't get it to look like I want it to look, or behave like I want it to behave. I know I'm missing something(s) important, but I'm just not getting it. My repo. I'm trying to build a macOS app, not an iOS app -- is that the problem, ultimately? SwiftUI isn't really intended for macOS? It would be good to know that.

If this is too much to ask for as hand-holding, someone let me know and I'll post a $100 job on upwork. I'm that frustrated. My brain just doesn't have the right neuro-receptors for SwiftUI. It's incredibly frustrating to have an idea for an app, work out what the core code should be, but not be able to get the UI to look or act even halfway nice. If it's more than $100 worth of work, someone let me know how much.

Below is some scribbling that may or may not illuminate what I'm trying to do. Any and all advice appreciated. Downvotes and nasty comments not appreciated. If I wanted downvotes and nasty comments, I'd go to StackExchange or /r/SwiftUI. Cheers

Unsurprisingly, I can't figure out how to get this image to show up in the forum:

https://imgur.com/a/ycoqItx

   

Hey!

First of all, at the moment, your UI code looks pretty good, nothing stands out to me as bad or wrong. What I think you need to do is to draw the expected design somewhere, like a paint app, or more professional and suited apps like Figma or photoshop. From what I can see on the image, nothing should be too hard to do after that, except maybe for the slider-textfield control you want to have. AFAIK, there's no such standard view, so you would need to create your own, or you can use a slider, as you proposed in the notes.

Another thing you might want to do is check the standard library of views and especially styles because views like picker can have multiple styles, almost unrelated to one another. After that, you will understand more clearly what you can use right off the bat, and what you do customly.

The multiple disclosure thing you want to have is also correctly done with ForEach view, though you need to make your view model (Settings) reflect that might have multiple rings. That means ringRadiusFraction should be an array of Doubles. Btw, you don't need to initialize Double like Double(0.5). The default floating-point literal is Double already. Then, ForEach will look like ForEach(0..<ringRadiusFraction.count, id: \.self) { ... }. This is a not-so-good solution, but it will do for the first time. If you want to enhance it in the future, you will need to generate, or somehow assign unique IDs to the rings themself, which have to become Identifiable structs.

Swipe actions are another kind of tricky part, but only pre macOS 12. Delete action can be made available on any version of SwiftUI if your ring settings will be rendered as List, instead of ForEach and using onDelete view modifier. More info here.

As for duplicate and any other swipe actions, the easy way is only available for macOS 12+ using swipeActions view modifier, before that, I would guess the easiest option would be to resort back to UIKit for this specific part.

The last thing is about moving values around the app. Again, you here already done pretty much everything needed here, your ContentView holds the reference to the Settings object, passing it to SettingsView, which manipulates it. Your ArenaScene receives updates, just by virtue of Settings being a reference type. One thing here is I don't think @ObservedObject in ArenaScene does anything, though I have not dealt with SpriteKit to tell for sure.

I hope that helps somewhat and you will get through your struggles and materialize the idea that you have :)

1      

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.

Learn More

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

Reply to this topic…

You need to create an account or log in to reply.

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.