Your First iOS & SwiftUI App: An App from Scratch, Episode 26: Challenge: Calculate the Difference | raywenderlich.com

Try improving the algorithm to calculate the difference so it is written in fewer lines of code.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/28797163-your-first-ios-swiftui-app-an-app-from-scratch/lessons/26

Sorry, I’m feeling a little stupid here… Can someone explain to me what this does?

    func points(sliderValue: Int) -> Int {
        var difference: Int = self.target - sliderValue
        if difference < 0 {
            difference *= -1
        }