Skip to content

Avoid use of "as!" (forced downcasts) #114

Closed

Description

@alykhank

Avoid using the forced form of the type cast operator (as!), covered in The Swift Programming Language: Type Casting — Downcasting.
Preferred

if let movie = item as? Movie {
    print("Movie: '\(movie.name)', dir. \(movie.director)")
}

Not Preferred

let movie = item as! Movie
print("Movie: '\(movie.name)', dir. \(movie.director)")
let someForceCast = NSNumber() as! Int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions