I have an Objective-C class in a .h
file similar to this:
@interface GlobalTags : NSObject
extern const BOOL showMessages;
@end
and a .m
file similar to this:
@implementation GlobalTags
const BOOL showMessages = YES;
@end
In summary, what I want is to have several global variables with no need to instance a class, just to access them by importing their file. What is the best way to do this in Swift?
Thanks
EDIT: regarding getting Swift global variables from Objective-C code, it is not possible (see this post).
To make such global variables visible in Objective-C code, I'm doing this in the Swift file:
class GlobalTags: NSObject {
static let showMessages: Bool = true;
}
Would this be the correct/best way to do?
it's simple. In your Constants.swift file:
let kStringConstKey : String = "YourKey"
let kBoolConstKey : Bool = true
let kIntConstKey : Int = 34
let kDoubleConstKey : Double = 25.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With