Error[8]: Undefined offset: 13, 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(

带有args的Swift函数…传递给带有args的另一个函数

与(Objective-)C中类似,您不能将变量参数列表直接传递给另一个函数。您必须创建一个

CVaListPointer

(与
va_list
C语言中的Swift等效)并调用一个带有
CVaListPointer
参数的函数。

所以这可能是您要寻找的:

extension String {    func getLocalizeWithParams(args : CVarArgType...) -> String {        return withVaList(args) { NSString(format: self, locale: NSLocale.currentLocale(), arguments: 
withVaList()``CVaListPointer
) } as String }}

NSString
从给定的参数列表创建一个,并以该指针作为参数调用闭包。

示例(来自

let msg = "%@:  %fn".getLocalizeWithParams("Cost", 1234.56)print(msg)
文档):

Cost:  1,234.560000

美国地区的输出:

Cost:  1.234,560000

德语语言环境的输出:

更新:

Swift 3/4/5开始,

String(format: String, locale: Locale?, arguments: [CVarArg])
可以将参数传递给

extension String {    func getLocalizeWithParams(_ args : CVarArg...) -> String {        return String(format: self, locale: .current, arguments: args)    }}

直:

[+++]


)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, 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)
带有args的Swift函数…传递给带有args的另一个函数_随笔_内存溢出

带有args的Swift函数…传递给带有args的另一个函数

带有args的Swift函数…传递给带有args的另一个函数,第1张

带有args的Swift函数…传递给带有args的另一个函数

与(Objective-)C中类似,您不能将变量参数列表直接传递给另一个函数。您必须创建一个

CVaListPointer

(与
va_list
C语言中的Swift等效)并调用一个带有
CVaListPointer
参数的函数。

所以这可能是您要寻找的:

extension String {    func getLocalizeWithParams(args : CVarArgType...) -> String {        return withVaList(args) { NSString(format: self, locale: NSLocale.currentLocale(), arguments: 
withVaList()``CVaListPointer
) } as String }}

NSString
从给定的参数列表创建一个,并以该指针作为参数调用闭包。

示例(来自

let msg = "%@:  %fn".getLocalizeWithParams("Cost", 1234.56)print(msg)
文档):

Cost:  1,234.560000

美国地区的输出:

Cost:  1.234,560000

德语语言环境的输出:

更新:

Swift 3/4/5开始,

String(format: String, locale: Locale?, arguments: [CVarArg])
可以将参数传递给

extension String {    func getLocalizeWithParams(_ args : CVarArg...) -> String {        return String(format: self, locale: .current, arguments: args)    }}

直:



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

原文地址: http://outofmemory.cn/zaji/5560250.html

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

发表评论

登录后才能评论

评论列表(0条)

保存