2

How i can use global constants like:

#define EXAMPLE 123

from Objective-C in Swift???

I need to use string constants, which must be defined in AppDelegate to use in all App with #include "AppDelegate.h" in each class files.

Ivan Trubnikov
  • 177
  • 1
  • 8
  • 1
    Make one constant file and Declare all constants there. If you r using objective c then make one pch file & import that constant file OR if you use swift then you can directly access that constant without importing anything – Jitendra Modi Oct 04 '16 at 08:43

2 Answers2

3

I suggest making a structure, in a seperate file, with its properties as let constants. So something like this

struct myConstants {
    static let firstConstant = "hello"
    static let secondConstant = "goodbye"
}
Caspar Wylie
  • 2,818
  • 3
  • 18
  • 32
2

Just create a Struct class and make each property/function static.

struct Global {
    static var test = "Some value"
}

Call it Global.test

Rashwan L
  • 38,237
  • 7
  • 103
  • 107