Open menu with table of contents KennDeinZeichen
Logo of Stuttgart Media University for light theme Logo of Stuttgart Media University for dark theme
Stuttgart Media University

1 Abstract

German license plates. There are over 700 different ones. Find them. Collect them. It's a game.

50%

2 Preview

50%

50%

3 Final Project

50%

50%

50%

50%

4 Starter Project

Starter Project KennDeinZeichen

5 Live Demo

  • Added NavigationStack and navigationTitle (No NavigationLink yet)
  • Import JSON Loader
  • Modified List so it imports the new data. With ?? if data is nil
  • Add new Text (origin) and spacer to list

5.1 Summary

  • What does the App do so far?

5.2 Task

  • Start with the following App 02 KennDeinZeichen Model Loading

  • The Sample Data only contains the minimum data. Check the JSON file contents (Inside Assets).

  • Modify either the Struct or the Import (Google on how to import custom JSON within Swift).

  • Add all missing elements.

  • Replace the old ...Sample with the new file.

Hints:

  • Look at the JSON structure - what additional fields are available?
  • Properties that might not always be present should be optional (String?)
  • The Decodable protocol automatically maps JSON keys to struct properties with matching names
  • If JSON keys differ from your property names, you can use CodingKeys enum

6 Live Demo

  • Build Model or copy it (Show all added components) (e.g. the Task)
  • Build LicensePlate custom view (simple)
  • Add simple custom view to List view. Flip both license and origin

6.1 Task

03 Project with custom Plate

Build a Struct that supports valid license plates

Requirements The LicensePlate shall be a Struct

  • Contain no more than 8 characters
  • The District can have 1 to 3 letters
  • The Separation Letters can have 1 to 2 letters
  • The Separation Number can have 1 to 4 digits
  • The Suffix can either have None, an E for Electric, or an H for Historic. (Use a String Enum for that)

The struct shall have a failable init method. (Failable inits are marked with init? and can return nil if validation fails. Use Xcode autocomplete for help.)

Create a computed variable that will return the LicensePlate like: HH MZ 4224E (See the spaces!)

Hints:

  • A failable init looks like: init?(district: String, letters: String, numbers: String, suffix: String?)
  • Use guard statements to validate each component's length
  • Return nil if any validation fails
  • For the enum, consider: enum Suffix: String { case electric = "E", historic = "H" }
  • The computed variable could be named formatted and use string interpolation: "\(district) \(letters) \(numbers)\(suffix ?? "")"