Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 3 conversion gets 'Int1' is not convertible to 'Bool'

Tags:

ios

xcode8

swift3

I'm converting Swift 2 code that compiles and runs to Swift 3 and am getting the following error:

'Int1' is not convertible to 'Bool'

The code is as follows:

isUpdated = sharedInstance.database!.executeUpdate(
"UPDATE Coin_Table SET upgrade=?, grade=?, WHERE coin_id=?", 
withArgumentsInArray: [
coinInfo.upgrade, (coinInfo.grade != nil) ? coinInfo.grade! : NSNull(), 
coinID])

The code above is using FMDB with the method defined in FMDB.h as

- (BOOL)executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments;

When compiling my code above it flags the "(coinInfo.grade !=" and gives the error.

I tried simplifying it to see if it would still happen:

let theArray: NSArray = [true ? "foo" : NSNull()]

and still get the same error, this time it flags the "true".

Screenshot of error

I've done a bunch of searches on this and haven't found anything close other than https://bugs.swift.org/browse/SR-2372 but that is an issue with tuples which I wouldn't think would affect my code.

Can anyone shed some light on this or suggest a workaround if it is a compiler bug?

Thanks

like image 265
KevinR Avatar asked Sep 17 '16 16:09

KevinR


1 Answers

As you wrote yourself your issue is the same as a one described here. Bugs happens ))

Why not just to use a temporary variable to fix it:

let hasGrade: Any = (coinInfo.grade != nil) ? coinInfo.grade! : NSNull()
isUpdated = sharedInstance.database!.executeUpdate(
"UPDATE Coin_Table SET upgrade=?, grade=?, WHERE coin_id=?", 
withArgumentsInArray: [
coinInfo.upgrade, hasGrade, 
coinID])
like image 175
Avt Avatar answered Nov 10 '22 18:11

Avt