Error[8]: Undefined offset: 3, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我在 swift 3中有以下代码: class StringUtility { static func Localizer(tableName: String?) -> (_ key: String, _ params: CVarArg...) -> String { return { (key: String, params: CVarArg...) in let c 我在 swift 3中有以下代码:

class StringUtility {  static func Localizer(tablename: String?) -> (_ key: String,_ params: CVararg...) -> String {    return { (key: String,params: CVararg...) in      let content = NSLocalizedString(key,tablename: tablename,comment: "")      if params.isEmpty {        return content      }      print(params) ->>>>>> this prints [[[Wells Fargo]]]      return Nsstring.init((format: content,arguments: getVaList(params))) as String    }  }}func localizationHelper(tablename: String,key: String,params: CVararg...) -> String {  let t = StringResourceUtility.Localizer(tablename: tablename)  print(params) - >>>>>>>>>> this prints [[Wells Fargo]]  return t(key,params)}

如果在上面两个函数中看到print语句,每次在函数内部传递CVararg时都会附加[],导致输出错误的本地化字符串.

1)CVararg不能像上面的代码一样多次传递?
2)如何解决这个问题?

解决方法 你不能将变量参数列表传递给另一个函数
必须传递一个CVaListPointer.还有withVaList应该
用来代替getVaList:

class StringResourceUtility {    static func Localizer(tablename: String?) -> (_ key: String,_ params: CVaListPointer) -> String {        return { (key: String,params: CVaListPointer) in            let content = NSLocalizedString(key,comment: "")            return Nsstring(format: content,arguments: params) as String        }    }}func localizationHelper(tablename: String,params: CVararg...) -> String {    let t = StringResourceUtility.Localizer(tablename: tablename)    return withVaList(params) { t(key,
let s = localizationHelper(tablename: "table",key: "%@ %@",params: "Wells","Fargo")print(s) // Wells Fargo
) } }

例:

[+++] 总结

以上是内存溢出为你收集整理的swar 3问题与CVarArg被多次传递全部内容,希望文章能够帮你解决swar 3问题与CVarArg被多次传递所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
swar 3问题与CVarArg被多次传递_app_内存溢出

swar 3问题与CVarArg被多次传递

swar 3问题与CVarArg被多次传递,第1张

概述我在 swift 3中有以下代码: class StringUtility { static func Localizer(tableName: String?) -> (_ key: String, _ params: CVarArg...) -> String { return { (key: String, params: CVarArg...) in let c 我在 swift 3中有以下代码:

class StringUtility {  static func Localizer(tablename: String?) -> (_ key: String,_ params: CVararg...) -> String {    return { (key: String,params: CVararg...) in      let content = NSLocalizedString(key,tablename: tablename,comment: "")      if params.isEmpty {        return content      }      print(params) ->>>>>> this prints [[[Wells Fargo]]]      return Nsstring.init((format: content,arguments: getVaList(params))) as String    }  }}func localizationHelper(tablename: String,key: String,params: CVararg...) -> String {  let t = StringResourceUtility.Localizer(tablename: tablename)  print(params) - >>>>>>>>>> this prints [[Wells Fargo]]  return t(key,params)}

如果在上面两个函数中看到print语句,每次在函数内部传递CVararg时都会附加[],导致输出错误的本地化字符串.

1)CVararg不能像上面的代码一样多次传递?
2)如何解决这个问题?

解决方法 你不能将变量参数列表传递给另一个函数
必须传递一个CVaListPointer.还有withVaList应该
用来代替getVaList:

class StringResourceUtility {    static func Localizer(tablename: String?) -> (_ key: String,_ params: CVaListPointer) -> String {        return { (key: String,params: CVaListPointer) in            let content = NSLocalizedString(key,comment: "")            return Nsstring(format: content,arguments: params) as String        }    }}func localizationHelper(tablename: String,params: CVararg...) -> String {    let t = StringResourceUtility.Localizer(tablename: tablename)    return withVaList(params) { t(key,
let s = localizationHelper(tablename: "table",key: "%@ %@",params: "Wells","Fargo")print(s) // Wells Fargo
) } }

例:

总结

以上是内存溢出为你收集整理的swar 3问题与CVarArg被多次传递全部内容,希望文章能够帮你解决swar 3问题与CVarArg被多次传递所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1009463.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存