I want to discuss some problems on using operator on optional values.
Here is my code:
let value: Bool? = false
let result = !value // the variable ‘result' is expected Optional<Bool> type,
// if value is nil, then the result should be nil
// otherwise it returns the result of NOT operator.
This cannot work with Swift 2.1.
let value: Int? = 0
let result = value + 1 // the variable ‘result' is expected Optional<Int> type
// if value is nil, then the result should be nil
// otherwise it returns the result of NOT operator.
This is also cannot work with Swift 2.1.
If the basic value operator can work with optional types, it will save multiple lines in out code.
On 2016-02-16, at 10:40:48, Cao Jiannan via swift-evolution <swift-evolution@swift.org> wrote:
Hi all,
I want to discuss some problems on using operator on optional values.
Here is my code:
let value: Bool? = false
let result = !value // the variable ‘result' is expected Optional<Bool> type,
// if value is nil, then the result should be nil
// otherwise it returns the result of NOT operator.
This cannot work with Swift 2.1.
let value: Int? = 0
let result = value + 1 // the variable ‘result' is expected Optional<Int> type
// if value is nil, then the result should be nil
// otherwise it returns the result of NOT operator.
This is also cannot work with Swift 2.1.
If the basic value operator can work with optional types, it will save multiple lines in out code.