我正在尝试从NSUserdefaults中检索NSMutableArray。代码给了我一个例外:
[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object'
给我错误:
if let chatUsersJidArray = KUtility.getUserDefault(key: KChatUsersJid).mutableCopy() as? NSMutableArray
后来我使用下面的代码:
"Command failed due to signal:Segmentation fault:11"
然后{%ifequal ser_id 3%}
<label for="inputMobile" id="field-label" class="col-lg-3 col-md-3 col-sm-3 col-xs-3 control-label">Subscriber Id:</label>
{%else ifequal ser_id 5%}
<label for="inputMobile" id="field-label" class="col-lg-3 col-md-3 col-sm-3 col-xs-3 control-label">Phone No:</label>
{%else%}
<label for="inputMobile" id="field-label" class="col-lg-3 col-md-3 col-sm-3 col-xs-3 control-label">Mobile No:</label>
{%endif%}
{%endifequal%}
。任何帮助表示赞赏,我得到了许多其他解决方案,但没有使用可变副本。
答案 0 :(得分:0)
尝试使用原生Swift Array
结构。通过将其定义为var
,它会自动变为可变
if var chatUsersJidArray = KUtility.getUserDefault(key: KChatUsersJid) as? [ARRAY_TYPE] {
// use the chatUsersJidArray
}
答案 1 :(得分:-1)
直接从NSUserDefaults
获取值不会返回Mutable
个对象。为此,您需要抓取mutableCopy
if let chatUsersJidArray = KUtility.getUserDefault(key: KChatUsersJid) as? NSArray {
var arrChatJidMutable = chatUsersJidArray.mutableCopy()
//Now you can manipulate this array. Add / Remove / Update
}