Monday, August 18, 2014

Optional return values cannot have type

This'll crash if resultset is nil with "fatal error: unexpectedly found nil while unwrapping an Optional value":


var resultset: FMResultSet = db.executeQuery(
    "SELECT * FROM settings WHERE id = ?",
    withArgumentsInArray: [10]
)

While this will run without fatal:

var resultset = db.executeQuery(
    "SELECT * FROM settings WHERE id = ?",
    withArgumentsInArray: [10]
)

Update 25.08:
They can have a type if the question sign is used:

var resultset: FMResultSet? = db.executeQuery(
    "SELECT * FROM settings WHERE id = ?",
    withArgumentsInArray: [10]
)

No comments:

Post a Comment