Force Unwrap And Cast (ARCH9196)
Ce contenu n’est pas encore disponible dans votre langue.
Key swift.quality.force-unwrap · Severity warning · Category quality
Flags ! force unwraps, as! force casts and try! - crashes waiting for the case the type system warned about.
Incorrect
Section titled “Incorrect”let name = user!.namelet vc = segue.destination as! DetailViewControllerlet data = try! load()Correct
Section titled “Correct”guard let user else { return }guard let vc = segue.destination as? DetailViewController else { return }let data = try load()Use optional binding, as?, and propagate errors with try.