1. Home
  2. /
  3. Swift
  4. /
  5. Score Tracker

Score Tracker - Swift Typing CST Test

Loading…

Score Tracker — Swift Code

Tracks a score with increment, decrement, and reset closures.

var score = 0

let updateUI: () -> Void = { print("Score: \(score)") }
let increment: () -> Void = { score += 10; updateUI() }
let decrement: () -> Void = { score -= 5; updateUI() }
let reset: () -> Void = { score = 0; updateUI() }

// Simulate actions
updateUI()
increment()
decrement()
reset()

Swift Language Guide

Swift is a powerful, general-purpose, compiled programming language developed by Apple for iOS, macOS, watchOS, tvOS, and Linux. It emphasizes safety, performance, and modern programming practices.

Primary Use Cases

  • ▸iOS app development
  • ▸macOS desktop applications
  • ▸watchOS and tvOS apps
  • ▸Server-side applications using Swift on Linux
  • ▸Cross-platform development with SwiftUI or server frameworks

Notable Features

  • ▸Strong static typing with type inference
  • ▸Optionals to handle nullability safely
  • ▸Protocol-oriented programming
  • ▸Modern syntax with closures and generics
  • ▸SwiftUI for declarative UI development

Origin & Creator

Created by Apple Inc., primarily by Chris Lattner, and first released in 2014.

Industrial Note

Swift is specialized for Apple ecosystem development, including apps for iPhone, iPad, Mac, Apple Watch, and Apple TV, but can also be used on servers and Linux platforms.

More Swift Typing Exercises

Swift Optionals and ClosuresSwift Counter with ClosuresSwift Theme ToggleSwift Optional Binding ExampleSwift Health TrackerSwift Level TrackerSwift Coin CounterSwift Ammo TrackerSwift Star CollectorSwift Power-Up Timer

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher