swift - How do i create an optional var with no value inline -


i have method returns optional integer one:

func foo(bar:string) -> int? {     if(bar == "bar")     {         return 42     }     else     {         var nothing:int?         return nothing     } } 

i'd return no value without creating var, possible?

return nothing:int? 

would expect...

thanks in advance.

use

return nil 

you not need specify type - have provided in function return type already.


Comments

Popular posts from this blog

bash - Performing variable substitution in a string -

How to group boxplot outliers in gnuplot -