2

What is the best way to use global macros in Swift (If this is what is called, english is not my mother tongue sorry). I am looking for a way to have all the macros/keys in on place, maybe a class.

I used to put all my app keys in the Precompiled Header file (.phc), but like I saw in another post this is probably not the best practice:

Why .pch file not available in swift?

For example if I would like to have a bunch of constant keys that the values are just Int, what would you recommend to use in Swift?

Thanks in advance!

Community
  • 1
  • 1
Ruben X
  • 117
  • 1
  • 1
  • 6

2 Answers2

6

You can create a Swift file with everything you need as global functions if you really want. For example, create a new Swift file named Globals.swift. In this file, you do not need any class or struct declarations. Define functions at a global scope, and they are available the same as any other method, like the global contains method.

erdekhayser
  • 6,537
  • 2
  • 37
  • 69
  • 1
    Thanks! I will go with this one. Sorry I have not enough reputation to give you an up vote so far. – Ruben X Oct 06 '14 at 12:31
1

You could just create a Struct or an Enum at global scope.

Anorak
  • 3,096
  • 1
  • 14
  • 11