Ich versuche, ein Element in einem benutzerdefinierten Array einzufügen. Aber ich bekomme keinen Indexfehler mehr. Unten ist mein Code:CustomType Array einfügen Absturz in Swift 3.0
var newCGList = [TTCareGiverItem]()
if let snapshotItems = snapshot.value as? [String:Any]{
for (_, snapshotData) in snapshotItems {
let dict = snapshotData as? NSDictionary
if let cgList = dict?.value(forKey: "ul") as? NSDictionary {
for cg in cgList{
let cgKey = cg.key as! String
for ctr in 0 ..< self.careGiverList.count{
let key = self.careGiverList[ctr].id as String
if key == cgKey{
let order: Int = Int(cg.value as! String)!
let aCG = self.careGiverList[ctr]
aCG.order = order
newCGList.insert(aCG, at: ctr)
break
}
}
}
}
}
Was ich vermisse?
Was Sie brauchen, ist 'append (_ :)' nicht 'einfügen (_: at)' –
Ich muss in einer Reihenfolge Liste einfügen funktioniert nicht . – TechBee
@TechBee Warum verwenden Sie stattdessen einfügen? –