tonytran tonytran - 5 months ago 16
iOS Question

what is the difference when using var vs typealias

I am defining my function as the variable by using

typealias
and
var
( or
let
)

typealias IntFuction = (Int) -> Int

var IntFuction = (Int) -> Int


If am using
typealias
, there are no error at all. However if I am trying to use either
var
or
let
, I am getting the error like below

consecutive statement on a line must be separated by ";"


With the closure, it should be fine if you can use either
typealias
or
var
to define as a variable

Can anybody explain what is happening when I am using
var
to define the function as the variable

Answer

typealias IntFuction = (Int) -> Int. Define a type IntFuction same as (Int) -> Int

var IntFuction = (Int) -> Int is incorrect

var IntFuction: (Int) -> Int Declare a variable IntFuction has type: (Int) -> Int