草庐IT

Array_multisort

全部标签

ios - swift - fatal error : Array index out of range

我正在尝试用每个增加0.1的数字填充一个数组,例如:[0.1,0.2,0.3...]此代码给我错误:fatalerror:数组索引超出范围。我错过了什么?我觉得我在声明错误。我会把它存成Double类型的结构。我的代码importUIKitclassPrecoDomicilioViewController:UIViewController,UIPickerViewDelegate,UIPickerViewDataSource{@IBOutletvareuros:UIPickerView!varpickerData:[Double]=[]overridefuncviewDidLoad()

arrays - 线程 1 : EXE_BAD_INSTRUCTION | assigning an array of objects values

我制作了一个对象数组列表并尝试定义其中一个,起初它很好但是当我尝试调用定义对象的函数时它会给我一个错误“Thread1:EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,子代码0x0)我的代码是这样的:classColor{varRed:Bool=truefuncsetRed(input:Bool){self.Red=input}和classViewController:UIViewController{//CreatetheobjectarrayvarColors:[Color]=[]//asignvaluestothearrayinsideafunct

arrays - Array<T> 和 [T] 有什么区别?

这个问题在这里已经有了答案:Differencebetween[String]andArray(3个答案)关闭4年前。标题说明了一切。我期待通过Any?将一个数组交给我参数(不要问!我讨厌他们那样实现它!),我想测试这是否是我真正得到的。不确定我是否应该测试Array或[T]或者是否存在差异。

json - swift 4 : how to implement codable protocol for json array of different types

有人可以启发我如何为以下多种类型的json数组实现codableprotocol到swift结构吗?在下面的json素材数组中,可以是反射对象、视频对象或笔记对象。{"materials":[{"reflection":{"title":"3-2-1reflection","description":"pleasereflectaftertoday","questions":[{"question":"question1","answer":"answer1","answerImageUrl":"http://xxx"},{"question":"question1","answer"

ios - 核心 ML : UIImage from RGBA byte array not fully shown

结合CoreML,我尝试使用以下代码在UIImage中显示RGBA字节数组:CGColorSpaceRefcolorSpace=CGColorSpaceCreateDeviceRGB();CGContextRefcontext=CGBitmapContextCreate(bytes,width,height,8,4*width,colorSpace,kCGImageAlphaPremultipliedLast);CFRelease(colorSpace);CGImageRefcgImage=CGBitmapContextCreateImage(context);CGContextRel

arrays - 为什么我不能调用 reduce(into :) on an array literal in Xcode 9. 2?

我正在寻找一种将数组映射到字典的方法并找到了这个post.这很有帮助。我将该帖子中的代码复制到playground中并且可以正常工作。然后我决定更多地使用它:[1,2,3].reduce(into:[Int:String](),{$0[$1]=$1.description})我希望它返回[1:"1",2:"2",3:"3"]但出现编译错误:Cannotsubscriptavalueofincorrectorambiguoustype我试图减少到一个数组:[1,2,3].reduce(into:[Int](),{$0.append($1)})//Iamawarethatthisispoi

arrays - swift 2 : extension to Array that compares exact objects?

我想查明对象的确切实例是否在数组中。这似乎是一个非常有用的功能,所以我尝试扩展数组:extensionArray{funccontainsIdenticalObject(object:AnyObject)->Bool{ifself.count>0{for(_,objectToCompare)inself.enumerate(){ifobject===objectToCompare{returntrue}}}returnfalse}}我收到消息:error:binaryoperator'==='cannotbeappliedtooperandsoftype'AnyObject'and'E

arrays - Swift 2D Array Generic Extension - 访问二维的问题

我正在尝试将以下函数转换为二维数组的通用扩展。funcrotate(_input:[[Int]])->[[Int]]{letlength=input[0].countvarvalue=Array(repeating:[Int](),count:length)forindexin0..我特别困惑如何指定约束以允许我访问第二个维度。这是一次失败的尝试:extensionArraywhereElement:Collection,Element.Iterator.Element:Collection{privatefuncrotate(){letcount=self[0].count//Ele

swift - 从 Array<Dictionary<String,String>> 中提取字符串数组的有效方法

是否有一种有效的方法可以在不使用嵌套for循环的情况下从下面的AllData中获取包含“名称”字符串的数组?我得到的代码有效:“Alice”、“BradSmithMD”、“Dr.Quam”、“JenniferJohnson”、“JohnBanksMD”作为输出,但我想在没有嵌套for循环的情况下执行它,因为它效率不高On^2并且很难阅读?我在Xcode8.2中使用Swift3varAllData:Array>=[]overridefuncviewDidLoad(){super.viewDidLoad()AllData=[["pic":"Alice.png","name":"AliceS

iOS swift : How to store the index of all duplicate values in array?

让我们以我有这个数组为例:letdates=["01/02/16","02/02/16","03/02/16","01/02/16","02/02/16"]我喜欢做的是将每个String日期作为键存储在字典中,对于每个重复的键,我喜欢将其索引存储为数组,并将其与重复键。例如,01/02/16出现在索引0和3处。02/02/16出现在索引1和4处。我喜欢这样的字典:["01/02/16":[0,3],"02/02/16":[2,4],"03/02/16":[1]]我知道如何跟踪有多少重复条目是这样的:letdates=["01/02/16","01/02/16","02/02/16","