This code worked just fine in Swift 2.3 and I don't understand why I have to unwrap TestClass
to check if number is bigger than 4. This is whole point of chaining optionals, to save additional call.
Now to make this work, I have to check if testClass != nil
(or use implicit unwrap with if let
statement) and then check count.
Is this really the only way?
import UIKit
class testClass
{
var optionalInt:Int?
}
var test:testClass?
if test?.optionalInt > 4
{
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…