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

概述我有一系列的项目 struct Item { var id: String} 如何使用reduce函数将所有id附加到数组? 我尝试了什么: self.items.reduce([String](), { $0.0.append($0.1.id)}) 但编译显示错误: Contextual closure type ‘(_, [Item]) -> _’ expects 2 argumen 我有一系列的项目

struct Item {    var ID: String}

如何使用reduce函数将所有ID附加到数组?

我尝试了什么:

self.items.reduce([String](),{ 
struct Item {    var ID: String}var items = [Item(ID: "text1"),Item(ID: "text2")]let reduceResult = items.reduce([String](),{ 
let reduceResult = items.map { [+++].ID }
+ [.ID] } )reduceResult // ["text1","text2"]
.0.append([+++].1.ID)})

但编译显示错误:

Contextual closure type ‘(_,[Item]) -> _’ expects 2 arguments,but 1 was used in closure body

解决方法 如果你想用reduce来做,这里是Swift 3和4的片段:

[+++]

有两个问题:

> Reduce给你2个参数,而不是带有2个值的单个元组
>您无法编辑块中传递给您的参数,您必须返回新对象

但在这种情况下,最好的解决方案是使用map:

[+++] 总结

以上是内存溢出为你收集整理的swift – 使用reduce将struct的属性追加到数组全部内容,希望文章能够帮你解决swift – 使用reduce将struct的属性追加到数组所遇到的程序开发问题。

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

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

概述我有一系列的项目 struct Item { var id: String} 如何使用reduce函数将所有id附加到数组? 我尝试了什么: self.items.reduce([String](), { $0.0.append($0.1.id)}) 但编译显示错误: Contextual closure type ‘(_, [Item]) -> _’ expects 2 argumen 我有一系列的项目

struct Item {    var ID: String}

如何使用reduce函数将所有ID附加到数组?

我尝试了什么:

self.items.reduce([String](),{ 
struct Item {    var ID: String}var items = [Item(ID: "text1"),Item(ID: "text2")]let reduceResult = items.reduce([String](),{ 
let reduceResult = items.map { .ID }
+ [.ID] } )reduceResult // ["text1","text2"]
.0.append([+++].1.ID)})

但编译显示错误:

Contextual closure type ‘(_,[Item]) -> _’ expects 2 arguments,but 1 was used in closure body

解决方法 如果你想用reduce来做,这里是Swift 3和4的片段:

[+++]

有两个问题:

> Reduce给你2个参数,而不是带有2个值的单个元组
>您无法编辑块中传递给您的参数,您必须返回新对象

但在这种情况下,最好的解决方案是使用map:

[+++] 总结

以上是内存溢出为你收集整理的swift – 使用reduce将struct的属性追加到数组全部内容,希望文章能够帮你解决swift – 使用reduce将struct的属性追加到数组所遇到的程序开发问题。

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

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

概述我有一系列的项目 struct Item { var id: String} 如何使用reduce函数将所有id附加到数组? 我尝试了什么: self.items.reduce([String](), { $0.0.append($0.1.id)}) 但编译显示错误: Contextual closure type ‘(_, [Item]) -> _’ expects 2 argumen 我有一系列的项目

struct Item {    var ID: String}

如何使用reduce函数将所有ID附加到数组?

我尝试了什么:

self.items.reduce([String](),{ 
struct Item {    var ID: String}var items = [Item(ID: "text1"),Item(ID: "text2")]let reduceResult = items.reduce([String](),{ 
let reduceResult = items.map { .ID }
+ [.ID] } )reduceResult // ["text1","text2"]
.0.append(.1.ID)})

但编译显示错误:

Contextual closure type ‘(_,[Item]) -> _’ expects 2 arguments,but 1 was used in closure body

解决方法 如果你想用reduce来做,这里是Swift 3和4的片段:

[+++]

有两个问题:

> Reduce给你2个参数,而不是带有2个值的单个元组
>您无法编辑块中传递给您的参数,您必须返回新对象

但在这种情况下,最好的解决方案是使用map:

[+++] 总结

以上是内存溢出为你收集整理的swift – 使用reduce将struct的属性追加到数组全部内容,希望文章能够帮你解决swift – 使用reduce将struct的属性追加到数组所遇到的程序开发问题。

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

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

概述我有一系列的项目 struct Item { var id: String} 如何使用reduce函数将所有id附加到数组? 我尝试了什么: self.items.reduce([String](), { $0.0.append($0.1.id)}) 但编译显示错误: Contextual closure type ‘(_, [Item]) -> _’ expects 2 argumen 我有一系列的项目

struct Item {    var ID: String}

如何使用reduce函数将所有ID附加到数组?

我尝试了什么:

self.items.reduce([String](),{ 
struct Item {    var ID: String}var items = [Item(ID: "text1"),Item(ID: "text2")]let reduceResult = items.reduce([String](),{ 
let reduceResult = items.map { .ID }
+ [.ID] } )reduceResult // ["text1","text2"]
.0.append(.1.ID)})

但编译显示错误:

Contextual closure type ‘(_,[Item]) -> _’ expects 2 arguments,but 1 was used in closure body

解决方法 如果你想用reduce来做,这里是Swift 3和4的片段:

有两个问题:

> Reduce给你2个参数,而不是带有2个值的单个元组
>您无法编辑块中传递给您的参数,您必须返回新对象

但在这种情况下,最好的解决方案是使用map:

[+++] 总结

以上是内存溢出为你收集整理的swift – 使用reduce将struct的属性追加到数组全部内容,希望文章能够帮你解决swift – 使用reduce将struct的属性追加到数组所遇到的程序开发问题。

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

)
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)
swift – 使用reduce将struct的属性追加到数组_app_内存溢出

swift – 使用reduce将struct的属性追加到数组

swift – 使用reduce将struct的属性追加到数组,第1张

概述我有一系列的项目 struct Item { var id: String} 如何使用reduce函数将所有id附加到数组? 我尝试了什么: self.items.reduce([String](), { $0.0.append($0.1.id)}) 但编译显示错误: Contextual closure type ‘(_, [Item]) -> _’ expects 2 argumen 我有一系列的项目

struct Item {    var ID: String}

如何使用reduce函数将所有ID附加到数组?

我尝试了什么:

self.items.reduce([String](),{ 
struct Item {    var ID: String}var items = [Item(ID: "text1"),Item(ID: "text2")]let reduceResult = items.reduce([String](),{ 
let reduceResult = items.map { .ID }
+ [.ID] } )reduceResult // ["text1","text2"]
.0.append(.1.ID)})

但编译显示错误:

Contextual closure type ‘(_,[Item]) -> _’ expects 2 arguments,but 1 was used in closure body

解决方法 如果你想用reduce来做,这里是Swift 3和4的片段:

有两个问题:

> Reduce给你2个参数,而不是带有2个值的单个元组
>您无法编辑块中传递给您的参数,您必须返回新对象

但在这种情况下,最好的解决方案是使用map:

总结

以上是内存溢出为你收集整理的swift – 使用reduce将struct的属性追加到数组全部内容,希望文章能够帮你解决swift – 使用reduce将struct的属性追加到数组所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1006242.html

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

发表评论

登录后才能评论

评论列表(0条)

.0.append(", "pubDate": "2022-05-22", "upDate": "2022-05-22" }
保存
.0.append(', author : 'feed', cat_name : 'app', time_y_m : '2022年05月', time_d : '22', site_motto : '内存溢出' }; {script} {script}