Vinodh
Vinodh

Reputation: 5268

How to define custom localize constant in swift

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

Upvotes: 0

Views: 550

Answers (2)

nsinvocation
nsinvocation

Reputation: 7637

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")
}

Upvotes: 1

VRAwesome
VRAwesome

Reputation: 4803

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

Create parameterised string or macro in swift?

Upvotes: 0

Related Questions