NSMutableDictionary: mutating method sent to immutable object

前端 未结 6 2035
栀梦
栀梦 2021-01-11 10:24

The following code is returning an exception with the following error message \"mutating method sent to immutable object\" when attempting to removeObjectForKey



        
6条回答
  •  北海茫月
    2021-01-11 10:58

    i found same issue and found solution hope it will help some one.

    arrayOfferId = defaults.objectForKey("offerId")?.mutableCopy() as! NSMutableArray
    

    NSUserDefaults returns immutable objects, even if you put in mutable ones. You must call -mutableCopy on the returned value to get a mutable collection. so when you get value from NSUserDefault use mutableCopy()

提交回复
热议问题