D
D
Dmitry Zamula2021-09-14 20:20:54
Arrays
Dmitry Zamula, 2021-09-14 20:20:54

How to change the value of an array which is the elements of another array in swift 5?

I have an array that is initialized from JSON:
var someArray = json as! Array<Any>

This is an array of arrays

(someArray[i] as! Array<Any>)[j] = "some value"

but an error comes up saying that I cannot change the elements of an immutable array, although the elements of the original array are changed:

someArray[i] = someAnotherArray

How can I change the value of an array that is the elements of another mutable array?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
briahas, 2021-09-15
@briahas

It is necessary someArray[i]to assign the variable var A1. Update A1[j]. Assign A1 to someArray[i].

R
Roman Kerimov, 2021-10-14
@RomanKerimov

If this is an array of arrays, then you need to make an array of arrays from it:
var someArray = json as!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question