1

I looked at other questions but could not solve my problem.

Also, this code line crash in firebase crashlytics.

How can I fix? Thanks.

if AUserDefaults.read(key: UDKeys.local_token.rawValue) != nil {
    if !BTSingleton.sharedInstance.isContractVersionCheckRequired {
        getMyShipments()
    }
}

Error screenshot

bozkurt
  • 23
  • 4
  • What is `isContractVersionCheckRequired` in `BTSingleton`? Is it an implicitly unwrapped optional? You need to at least show the code for that object. – Paulw11 Mar 26 '21 at 19:44
  • @Paulw11 You are right, sorry. It is not optional. In BTSingleton: `var isContractVersionCheckRequired : Bool!` – bozkurt Mar 26 '21 at 19:57
  • It is an implicitly unwrapped optional (that is what the ! means). You need to check what is supposed to have assigned a value to that, or make it a true optional or at least conditionally unwrap it to see if it has a value. – Paulw11 Mar 26 '21 at 20:29

1 Answers1

0

Just need to make sure you have a bool before you read it. I would write it like this because I feel its cleaner:

// this approach compares the optional to false so if it is tru or nil it doesn't get executed
    if BTSingleton.sharedInstance.isContractVersionCheckRequired == false {
                getMyShipments()
            }

But you could write it like this it may be easier to understand:

// this approach safely unwraps the optional and then checks the value
    if let versionCheckRequired = BTSingleton.sharedInstance.isContractVersionCheckRequired, versionCheckRequired == false {
        getMyShipments()
    }
Daniel Lyon
  • 1,499
  • 10
  • 15