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

Hint: Troubleshooting multiple refreshes

Forums > SwiftUI

Here is a little hint I picked up on the internet (Karin Prater's youtube channel) for helping when you need to see where multiple unwanted refreshes are occuring. It has helped me a lot in just a couple days off trouble shooting.

Place this in places like a row item in a list, or pretty much anywhere, just comment it out when things are working. Uncomment occasionally to make sure no extra refreshes are happening. It basically changes the background color of views every time they are redrawn. Simple and obvious!

.background(Color.random())

and place this someplace convientient.

public extension Color {

     static func random( in range: ClosedRange<Double> = 0...1, randomOpacity: Bool = false ) -> Color {
        Color(
            red: .random(in: range),
            green: .random(in: range),
            blue: .random(in: range),
            opacity: randomOpacity ? .random(in: 0...1) : 1
        )
    }
}

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

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.