I am using Xcode 10.3 and Swift 5
I have a long struct with my Localizable Strings as follows:
import Foundation
struct Strings {
static let string1 = NSLocalizedString("String 1", comment:"")
....
}
I wanted to get rid of all the repetitive text (, comment:"" at the end of each struct item) so I wrote a one line extension as follows, in the same file, but I get the 'Use of undeclared type'
error in the extension
import Foundation
extension NSLocalizedString { // 'Use of undeclared type'
}
struct Strings {
static let string1 = NSLocalizedString("String 1", comment:"")
...
}
I tried to do the same with a String
extension and a new class LString
, and creating a class
method that returns the NSLocalizedString
object, with the same result
Why is NSLocalizedString
recognized inside the struct
but not in the extension?. (They are in the same file)
Am I missing something?