I have a JSON array (say, dataObj
) generated by SwiftyJSON and I try to remove its element like this:
let count=dataObj.count
for var m=x; m<count; ++m {
dataObj[m] = nil // there is no removeAtIndex() somehow
}
print(dataObj.count)
print(dataObj)
After execution, dataObj.count
remains the same and print
shows now dataObj
becomes
[null, null, null, ... ]
What's the way to really remove an element for SwiftyJSON?
object[0]
. Thenobject[1]
becomesobject[0
] and there is no index1
anymore. That causes a prettyout of bounds
exception. The only (safe) way to remove by index in a repeat loop is removing backwards. – Jann