草庐IT

edi-dictionary-viewer

全部标签

dictionary - 如何在 Kotlin 中将列表转换为 map ?

例如,我有一个字符串列表,例如:vallist=listOf("a","b","c","d")我想将其转换为map,其中字符串是键。我知道我应该使用.toMap()函数,但我不知道如何使用,也没有看到任何示例。 最佳答案 你有两个选择:第一个也是最高效的方法是使用associateBy函数,该函数采用两个lambdas来生成键和值,并内联map的创建:valmap=friends.associateBy({it.facebookId},{it.points})第二个,性能较差,是使用标准的map函数来创建toMap可以使用的Pair

IOS 在 NS(Mutable)Dictionary 中获取一个数组

我正在尝试在NSMutableDictionary中获取一个数组,如下所示:{coments=();"foto_user"="";fotos=({fecha="2012-08-3119:44:31";id=4926;nombre="image5773.jpg";posicion=0;ruta="img/";tipo=1;},{fecha="2012-08-3119:44:31";id=4927;nombre="image1779.jpg";posicion=0;ruta="img/";tipo=1;},{fecha="2012-08-3119:44:31";id=4928;nombre

swift - 在 Swift 中检查是否为 "dictionary item exists and is not blank"的紧凑方法?

我正在解析一个1970年代的文本文件(最初来自CDC6600),其中包含参数数量可变的行。这是一些示例...GW150.0000-1.00000.00000000.000001.00000.000.00667GE1FR000046.290.我正在使用split(是的,最终在Xcode7中修复了!)将其分解为一个数组,然后将非零值插入字典中,就像这样......letparts:[String]=original!.characters.split{$0==""||$0==","}.map{String($0).trim()}ifparts.count>1{data["I1"]=part

swift - 如何将 nil 作为 dictionary<String,AnyObject> 的参数传递

我有一个Dictionary类型的字典我需要将参数作为nil传递:letparams=["number":nil,"description":nil,"lang":"spa","byFee":true,"plan":data.Plan]asDictionaryrequest.HTTPBody=try!NSJSONSerialization.dataWithJSONObject(params,options:[])如果我这样做,我会得到一个错误:所以我尝试将词典更改为Dictionary但是如果我这样做,那么错误就会出现在请求中。HTTPBody: 最佳答案

ios - 从 Swift 3 中的 Dictionary<String, Any> 中获取值

这是一些代码:classMapViewController:UIViewController{vardico:Dictionary?overridefuncviewDidLoad(){super.viewDidLoad()letdest="\(String(describing:self.dico?.index(forKey:"adresse")))\(String(describing:self.dico?.index(forKey:"cp")))\(String(describing:self.dico?.index(forKey:"ville")))"print(dest)}}这

ios - 核心数据 : Inserting from array of dictionaries into SQLite database happens unsorted - set of Foreign Key therefore not possible

我遵循了如何从JSON文件解析并根据此预加载sqlite数据库的教程:https://medium.com/@jamesrochabrun/parsing-json-response-and-save-it-in-coredata-step-by-step-fb58fc6ce16f在这个方法中,解析的数据(字典数组)被映射:privatefuncsaveInCoreDataWith(array:[[String:AnyObject]]){_=array.map{self.createPhotoEntityFrom(dictionary:$0)}do{tryCoreDataStack.s

dictionary - 如何将值插入嵌套的 Swift 字典

我试图在字典中插入新的键值对,它嵌套在另一个Dictionary中:vardict=Dictionary>()dict.updateValue([1:"one",2:"two"],forKey:1)dict[1]?[1]//{Some"one"}ifvarinsideDic=dict[1]{//itisacopy,soIcan'tinsertpairthisway:insideDic[3]="three"}dict//still[1:[1:"one",2:"two"]]dict[1]?[3]="three"//Cannotassigntotheresultofthisexpressio

ios - Swift 减少/展平 Dictionary<String,Dictionary> 到 Dictionary

Convertthis["Cat":["A":1,"B":2],"Mat":["C":3,"D":4]]Into["A":1,"B":2,"C":3,"D":4]不使用循环。换句话说,使用reduce、flatmap等函数。source可以是类型Dictionary>到目前为止,我已经设法将Dictionary缩减为一个Dictionary数组letflatten=source.flatMap({(k,v)->[String:String]?inreturnv})//flatten=[["A":1,"B":2],["C":3,"D":4]]] 最佳答案

swift - 添加两个 [String : Int] dictionaries in Swift 的值

所以我尝试使用最新的Swift在Xcode中添加两个[String:Int]字典的值。我的代码如下所示。两个字典都有从q1到q23的键,并附有值。这就是随机数停在23的原因。keyq1在此函数中没有用处(这就是随机数从2开始的原因)。字典值由另一个ViewController在segue到此viewController期间给出,我不手动分配它们。字典中的值不需要是可选的,因为它们将被分配值以到达此viewController。我已经用谷歌搜索了一个小时,但我无法理解reduce、combine或map函数,因为它们适用于此,当我只想添加时做一些如此复杂的事情似乎我忽略了一个更简单的方法

Swift 更新数组中 Dictionary<String, Any> 内的值

我有一个字典数组,像这样varmyArray:[Dictionary]=[Dictionary]()我在类(class)的某处添加值,如下所示:varmyDict=Dictionary()myDict["Id"]="someUniqueId"myDict["v1"]=-42self.myArray.append(myDict)然后我尝试更新v1像这样在这个字典中:self.myArray.first(where:{$0["Id"]=="someUniqueId"})?["v1"]=-56但是,编译器告诉我:Cannotassignthroughsubscript:functioncal