BartyCrouch
BartyCrouch copied to clipboard
Define a marco or function,meet a error:Argument is not a literal string
Expected Behavior
no error
Actual Behavior
bartycrouch work,but throw a error with “bad entry in file /Users/xxx/Desktop/project_xxx/project_xxx/Macros.swift (line = 11): Argument is not a literal string.”
Steps to Reproduce the Problem
- define a function: func kkLocalizedString(_ key: String, comment: String) -> String { NSLocalizedString(key, tableName: "kkLocalizable", bundle: Bundle.main, value: "", comment: comment) }
- build project
- error
Specifications
- Version: 4.3.1
- Platform: iOS
- IDE Version:Xcode 12.2
My point
bartycrouch script run before compile sources, then the "key" of NSLocalizedString is not string
same here for:
public extension String {
func localized(_ parameters: CVarArg) -> Self {
String(format: NSLocalizedString(self, comment: ""), parameters)
}
func localized() -> Self {
NSLocalizedString(self, comment: "")
}
}
BartyCrouch is (currently) using Apples ExtractLocStrings
tool shipped as part of Xcode to detect Strings from code. So whatever limitations that tool has, the same limitations apply to BartyCrouch. Unfortunately, the approach you would like to take is not compatible with that tool, it only works with static strings.
I consider this an improvement, not a bug, so changing the tag. The expected behavior here was never documented to work.