Getting “mutating method sent to immutable object” error

后端 未结 3 1058
忘掉有多难
忘掉有多难 2020-12-12 03:06

I can\'t figure out what is causing this. Basically, a few different \'tasks\' are colliding with each other in my app. When i press a button, it runs this code just fine:

3条回答
  •  萌比男神i
    2020-12-12 03:37

    TO REMOVE AN OBJECT FROM PARTICULAR INDEX OF AN ARRAY. (Swift 3.0)

    let fullArray : NSArray = Userdefaults().value(forKey: "YOUR_ARRAY_STRING") as! NSArray
    var mutableArray : [AnyObject] = fullArray as [AnyObject]
    mutableArray.remove(at: INDEX_TO_REMOVE) //Eg: mutableArray.remove(at: 0)
    mutableArray.append(ARRAY_TO_APPEND)
    

提交回复
热议问题