Last active
          October 22, 2025 11:56 
        
      - 
      
- 
        Save cmsj/4767f94c91e3f0c45bd4f0b88c9fcfb7 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | func mightFail() -> Bool? { // Return type of this is actually Optional(Bool) because of the ? | |
| return nil | |
| } | |
| func main() { | |
| guard let result = mightFail() else { // This unwraps the Optional(Bool) | |
| print("lol get rekt") | |
| return | |
| } | |
| print("Result was: \(result == true)") // No compiler error about `result`, it is not possible for it to be nil here | |
| } | 
Or if you hate yourself:
func mightFail() -> Bool? {
  return nil
}
func main() {
  let result = mightFail()
  print("Result was \(result! == true)") // Optional(Bool) `result` is force-unwrapped with the !. Runtime crash if it's nil.
}
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Other variant is: