The shortest of them:
let LocalizedString = { NSLocalizedString($0, comment:"") }
But this is really a new feature. Just wrap the NSLocalizedString .
Perhaps you can use the undocumented @transparent attribute. It embeds a function call. see this topic in the developer forum .
@transparent LocalizedString(key:String) -> String { return LocalizedString(key, comment:"") }
But this is not recommended. Moreover, as long as my tests, all subsequent codes eventually emit the exact LLVM IR code with -O optimization.
script1 : with @transparent
import Foundation @transparent func LocalizedString(key:String) -> String { return LocalizedString(key, comment:"") } println(LocalizedString("key"))
script2 : without @transparent
import Foundation func LocalizedString(key:String) -> String { return LocalizedString(key, comment:"") } println(LocalizedString("key"))
script3 : direct call to NSLocalizedString
import Foundation func LocalizedString(key:String) -> String { return LocalizedString(key, comment:"") } println(NSLocalizedString("key", comment:""))
All of the above is intended to make a direct call to NSLocalizedString .
But the following code is different from the other:
script4 : closing the package
import Foundation let LocalizedString = { NSLocalizedString($0, comment:"") } println(NSLocalizedString("key", comment:""))
It is also built-in, but an additional refcount statement has been added to LocalizedString .
So, as a conclusion, you should just use this:
func LocalizedString(key:String) -> String { return LocalizedString(key, comment:"") }