Riya Pillai
Riya Pillai

Reputation: 31

what is the best way to create a class of global constants in Swift

In Objective-C, we used to do the following in our class files:

In the header:

extern NSString* const kSTRING_CONSTANT;

In the implementation:

NSString* const kSTRING_CONSTANT = @"a_string_constant";

What is the Swift equivalent of this?

Upvotes: 2

Views: 204

Answers (2)

DeFrenZ
DeFrenZ

Reputation: 2252

If all the constants are of the same type an enum could be the right way

Upvotes: 0

Anuj
Anuj

Reputation: 7067

The best way to deal with that type of constants is to create a Struct

struct GlobalConstants {
    static let someNotification = "TEST"
}
println(GlobalConstants.someNotification)

For further reference, refer to Swift Offical Guide or see the following link

How to create a global variable?

Upvotes: 2

Related Questions