BartyCrouch icon indicating copy to clipboard operation
BartyCrouch copied to clipboard

Define a marco or function,meet a error:Argument is not a literal string

Open HKevin1993 opened this issue 3 years ago • 2 comments

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

  1. define a function: func kkLocalizedString(_ key: String, comment: String) -> String { NSLocalizedString(key, tableName: "kkLocalizable", bundle: Bundle.main, value: "", comment: comment) }
  2. build project
  3. 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

HKevin1993 avatar Nov 27 '20 00:11 HKevin1993

same here for:

public extension String {
    func localized(_ parameters: CVarArg) -> Self {
        String(format: NSLocalizedString(self, comment: ""), parameters)
    }

    func localized() -> Self {
        NSLocalizedString(self, comment: "")
    }
}

nysander avatar Sep 23 '21 12:09 nysander

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.

Jeehut avatar Nov 13 '21 12:11 Jeehut