简体   繁体   English

R.Swift - 无法调用非函数类型 StringResource 的值

[英]R.Swift - Cannot call value of non-function type StringResource

Anyone experienced with using R.Swift who could help?任何有使用 R.Swift 经验的人可以提供帮助吗? I'm trying to consolidate code in our project which uses tons of R.string.localizable so that their occurrences aren't strewn all over the code and so that strings (and images) don't need to be reinstantiated again and again.我正在尝试合并我们项目中使用大量R.string.localizable的代码,这样它们的出现就不会散布在整个代码中,并且字符串(和图像)不需要一次又一次地重新实例化。 For this I want to add static lazy structs, like so:为此,我想添加静态惰性结构,如下所示:

private struct Text
{
    static let text1 = R.string.localizable.text1()
    static let text2 = R.string.localizable.text2()
    static let text3 = R.string.localizable.text3()
    static let text4 = R.string.localizable.text4
}

This works with simple strings but a problem arises when any of those string resources require arguments, like in case of text4 which therefore is declared as a String Resource and not a String :这适用于简单的字符串,但是当任何这些字符串资源需要参数时就会出现问题,例如text4因此被声明为String Resource而不是String

R.generated.swift: R.generated.swift:

static let text4 = Rswift.StringResource(key: "some.username", tableName: "Localizable", bundle: R.hostingBundle, locales: ["en", "ja"], comment: nil)

When text4 is required and I try to use it through my Text struct I get the error:当需要text4并且我尝试通过我的 Text 结构使用它时,我收到错误消息:

_userNameLabel?.text = Text.text4(userName, String.Empty)

Error: Cannot call value of non-function type StringResource错误: Cannot call value of non-function type StringResource

Is there a way to make this work?有没有办法使这项工作?

You can use您可以使用

static func text4(_ value: Int) -> String {
     R.string.localizable.text4(value)
}

and call Text.text4(10)并调用Text.text4(10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 快速错误:无法调用非函数类型“ SKSpriteNode”的值 - Swift error: Cannot call value of non-function type “SKSpriteNode” 在Swift 3中无法调用非函数类型'UICollectionView'的值 - Cannot Call Value of Non-Function Type 'UICollectionView' in Swift 3 ResponseSerializer'无法使用Swift 3调用非函数类型'NSHTTPURLResponse?'的值 - ResponseSerializer 'cannot call value of non-function type 'NSHTTPURLResponse?'' with Swift 3 无法调用非函数类型的值 '((AnyObject) -> AnyObject?)!' - 斯威夫特 3 - Cannot call value of non-function type '((AnyObject) -> AnyObject?)!' - Swift 3 错误:Swift 3上的“无法调用非函数类型的值” - Error: 'Cannot call value of non-function type' on Swift 3 无法调用非功能类型的值 - Cannot call value of non-function type 无法调用非功能类型的值 - Cannot call value of non-function type Swift:类型的值没有成员,无法调用非函数类型的值 - Swift: value of type has no member, cannot call value of non-function type 无法在 Swift 中的 function 错误中调用非函数类型 'SwipeCard' 的值 - Cannot call value of non-function type 'SwipeCard' in the function error in Swift 无法调用非函数类型'JSON'的值,如何从Swift中的块返回值 - Cannot call value of non-function type 'JSON', How can I return value from block in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM