简体   繁体   中英

'NSError' is not convertible to 'UInt8'

Although i have looked through the other "not convertible to UInt8" answers, I have not found one that I understand.

Can anyone tell me what is going on?

the below code is throwing the error - 'NSError' is not convertible to 'UInt8'

if( error != nil) {...}

Can anyone explain why checking if the error is nil would throw this "error" haha.

I can get the error to go away by making the nil option and changing the code to

if( error != nil!) {...}

Am I doing that correctly? Should i be doing something else instead?

Perhaps that error message isn't as useful as it should be, but the compiler is correct for complaining here. Notice that in the error you're receiving that the NSError type that it's complaining about is NSError , not NSError? or NSError! .

This means that your error variable is of the non-optional NSError type and therefore can never be nil, and making the nil check unnecessary. I think you will find that if you redeclare your error object as either an optional, or an implicitly unwrapped optional, your code will work just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM