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(

概述我有字典[String:[Object]].每个对象都有.name 是否可以在字典上使用.filter返回只包含过滤值的字典? 如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值. struct Obj { let name: String}let o1 = Obj(name: "one")let o 我有字典[String:[Object]].每个对象都有.name

是否可以在字典上使用.filter返回只包含过滤值的字典?

如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值.
struct Obj {    let name: String}let o1 = Obj(name: "one")let o2 = Obj(name: "two")let o3 = Obj(name: "three")let dict = ["a": [o1,o2],"b": [o3]]

现在假设您想要一个对象具有“两个”名称的字典键:

过滤解决方案

let filteredKeys = dict.filter { (key,value) in value.contains({ 
let filteredKeys = dict.flatMap { (str,arr) -> String? in    if arr.contains({ 
var filteredKeys = [String]()for (key,value) in dict {    if value.contains({ [+++].name == "two" }) {        filteredKeys.append(key)    }}print(filteredKeys)
.name == "two" }) { return str } return nil}print(filteredKeys)
.name == "two" }) }.map { [+++].0 }print(filteredKeys)

使用flatMap和包含的解决方案

[+++]

带循环的解决方案

[+++] 总结

以上是内存溢出为你收集整理的swift – 使用数组作为值过滤字典全部内容,希望文章能够帮你解决swift – 使用数组作为值过滤字典所遇到的程序开发问题。

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

)
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(

概述我有字典[String:[Object]].每个对象都有.name 是否可以在字典上使用.filter返回只包含过滤值的字典? 如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值. struct Obj { let name: String}let o1 = Obj(name: "one")let o 我有字典[String:[Object]].每个对象都有.name

是否可以在字典上使用.filter返回只包含过滤值的字典?

如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值.
struct Obj {    let name: String}let o1 = Obj(name: "one")let o2 = Obj(name: "two")let o3 = Obj(name: "three")let dict = ["a": [o1,o2],"b": [o3]]

现在假设您想要一个对象具有“两个”名称的字典键:

过滤解决方案

let filteredKeys = dict.filter { (key,value) in value.contains({ 
let filteredKeys = dict.flatMap { (str,arr) -> String? in    if arr.contains({ 
var filteredKeys = [String]()for (key,value) in dict {    if value.contains({ .name == "two" }) {        filteredKeys.append(key)    }}print(filteredKeys)
.name == "two" }) { return str } return nil}print(filteredKeys)
.name == "two" }) }.map { [+++].0 }print(filteredKeys)

使用flatMap和包含的解决方案

[+++]

带循环的解决方案

[+++] 总结

以上是内存溢出为你收集整理的swift – 使用数组作为值过滤字典全部内容,希望文章能够帮你解决swift – 使用数组作为值过滤字典所遇到的程序开发问题。

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

)
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(

概述我有字典[String:[Object]].每个对象都有.name 是否可以在字典上使用.filter返回只包含过滤值的字典? 如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值. struct Obj { let name: String}let o1 = Obj(name: "one")let o 我有字典[String:[Object]].每个对象都有.name

是否可以在字典上使用.filter返回只包含过滤值的字典?

如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值.
struct Obj {    let name: String}let o1 = Obj(name: "one")let o2 = Obj(name: "two")let o3 = Obj(name: "three")let dict = ["a": [o1,o2],"b": [o3]]

现在假设您想要一个对象具有“两个”名称的字典键:

过滤解决方案

let filteredKeys = dict.filter { (key,value) in value.contains({ 
let filteredKeys = dict.flatMap { (str,arr) -> String? in    if arr.contains({ 
var filteredKeys = [String]()for (key,value) in dict {    if value.contains({ .name == "two" }) {        filteredKeys.append(key)    }}print(filteredKeys)
.name == "two" }) { return str } return nil}print(filteredKeys)
.name == "two" }) }.map { .0 }print(filteredKeys)

使用flatMap和包含的解决方案

[+++]

带循环的解决方案

[+++] 总结

以上是内存溢出为你收集整理的swift – 使用数组作为值过滤字典全部内容,希望文章能够帮你解决swift – 使用数组作为值过滤字典所遇到的程序开发问题。

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

)
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(

概述我有字典[String:[Object]].每个对象都有.name 是否可以在字典上使用.filter返回只包含过滤值的字典? 如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值. struct Obj { let name: String}let o1 = Obj(name: "one")let o 我有字典[String:[Object]].每个对象都有.name

是否可以在字典上使用.filter返回只包含过滤值的字典?

如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值.
struct Obj {    let name: String}let o1 = Obj(name: "one")let o2 = Obj(name: "two")let o3 = Obj(name: "three")let dict = ["a": [o1,o2],"b": [o3]]

现在假设您想要一个对象具有“两个”名称的字典键:

过滤解决方案

let filteredKeys = dict.filter { (key,value) in value.contains({ 
let filteredKeys = dict.flatMap { (str,arr) -> String? in    if arr.contains({ 
var filteredKeys = [String]()for (key,value) in dict {    if value.contains({ .name == "two" }) {        filteredKeys.append(key)    }}print(filteredKeys)
.name == "two" }) { return str } return nil}print(filteredKeys)
.name == "two" }) }.map { .0 }print(filteredKeys)

使用flatMap和包含的解决方案

带循环的解决方案

[+++] 总结

以上是内存溢出为你收集整理的swift – 使用数组作为值过滤字典全部内容,希望文章能够帮你解决swift – 使用数组作为值过滤字典所遇到的程序开发问题。

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

)
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 – 使用数组作为值过滤字典_app_内存溢出

swift – 使用数组作为值过滤字典

swift – 使用数组作为值过滤字典,第1张

概述我有字典[String:[Object]].每个对象都有.name 是否可以在字典上使用.filter返回只包含过滤值的字典? 如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值. struct Obj { let name: String}let o1 = Obj(name: "one")let o 我有字典[String:[Object]].每个对象都有.name

是否可以在字典上使用.filter返回只包含过滤值的字典?

如果我理解你的问题,你需要[String:[Object]]字典的键,其中每个Object都有一个name属性,并且该属性具有给定值.
struct Obj {    let name: String}let o1 = Obj(name: "one")let o2 = Obj(name: "two")let o3 = Obj(name: "three")let dict = ["a": [o1,o2],"b": [o3]]

现在假设您想要一个对象具有“两个”名称的字典键:

过滤解决方案

let filteredKeys = dict.filter { (key,value) in value.contains({ 
let filteredKeys = dict.flatMap { (str,arr) -> String? in    if arr.contains({ 
var filteredKeys = [String]()for (key,value) in dict {    if value.contains({ .name == "two" }) {        filteredKeys.append(key)    }}print(filteredKeys)
.name == "two" }) { return str } return nil}print(filteredKeys)
.name == "two" }) }.map { .0 }print(filteredKeys)

使用flatMap和包含的解决方案

带循环的解决方案

总结

以上是内存溢出为你收集整理的swift – 使用数组作为值过滤字典全部内容,希望文章能够帮你解决swift – 使用数组作为值过滤字典所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存