I am new to swift 2 . I know define macro in objective c as
#define MYAPPCLocalize(Key) NSLocalizedStringFromTable(Key, APP_DELEGATE.currentStrings, @"N/A")
But how can i declare like the same in swift . Please help me
From Apple's docs :
Declare simple macros as global constants, and translate complex macros into functions.
You can translate your code this way:
func MYAPPCLocalize(key: String) -> String {
return NSLocalizedStringFromTable(key, APP_DELEGATE.currentStrings, "N/A")
}
I had same problem.
Actually in swift there no concept of Macros. If you want to create simple macro then you can create it with let
keyword which treated as a macro or something like static variable(attribute).
If you want to create parameterised macro, then create func
with parameters and return type.
Follow solution provided in this link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.