Swift Language Type Casting

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • let name = json["name"] as? String ?? "" // Output: john

  • let name = json["name"] as? String // Output: Optional("john")

  • let name = rank as? Int // Output: Optional(1)

  • let name = rank as? Int ?? 0 // Output: 1

  • let name = dictionary as? [String: Any] ?? [:] // Output: ["name" : "john", "subjects": ["Maths", "Science", "English", "C Language"]]



Got any Swift Language Question?