Your First iOS & SwiftUI App: An App from Scratch

Feb 13 2023 · Swift 5.7, iOS 16, Xcode 14

Part 3: Coding in Swift

28. Type Inference

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 27. Variables & Constants Next episode: 29. Conclusion

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

We’ve now reduced our points(sliderValue:) method to just a few lines of code.

  let difference = abs(target - sliderValue)
  let awardedPoints = 100 - difference
var target = Int.random(in: 1...100)
var score = 0
var round = 1

ContentView.swift

Let’s go to ContentView.swift, and we can clean up some of these as well.

@State private var alertIsVisible = false
@State private var sliderValue = 50.0
@State private var game = Game()
let roundedValue = Int(sliderValue.rounded())
return 100 - difference
return 100 - abs(target - sliderValue)
100 - abs(target - sliderValue)