[swift-evolution] optional variable with ternary operator

Saagar Jha saagar at saagarjha.com
Mon May 8 11:13:49 CDT 2017


Well, you’re not allowed to compare optionals any more. You can try binding the value to an Int, so that it’s not an optional anymore:

if let number = number {
	let result = number > 0 ? 1 : 2
}

Either way, you’ll have to decide what you think should happen when number is nil.

Saagar Jha

> On May 8, 2017, at 00:36, Suresh Kansujiya via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hey,
> 
> i am using ternary operator with optional variable. like below ex.
> 
> var number:Int?
> let result = number > 0 ? 1 : 2  
> here i am getting this waring : comparison operators with optionals were removed from the Swift Standard Library. Consider refactoring the code to use the non-optional operators
> 
> Note : i must need to use ternary operator for checking.
> 
> Regards
> Suresh Kansujiya
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170508/fc884ced/attachment-0001.html>


More information about the swift-evolution mailing list