Search code examples
iosswiftvariablesmacrospch

How to Declare Global Variable in Swift?


I am creating an App in which I have to declare some constant as global. in Obj C I could use pch file but I don't know how to define in Swift? For Example

in Obj C .pch file if I declare

define Red [UIColor redColor]

then it works through out application.


Solution

  • All you need to do is create a Constants.swift (or what ever you want to name it) file and then add what ever constants you need into it.

    let myVariable = "Some Value"
    let myOtherVariable = "Something Else"
    

    They will then be available throughout your application.