简体   繁体   English

__NSDictionaryI setObject:forKey:崩溃

[英]__NSDictionaryI setObject:forKey: Crash

The problem is that I am mutating a NSDictionary , but even after getting a mutableCopy , the app crashes. 问题是我正在更改NSDictionary ,但是即使获取了mutableCopy ,应用程序也会崩溃。

Below is Method for copy : 以下是复制方法

+ (NSMutableDictionary *)updateQuery:(NSMutableDictionary *)currentQuery toSearchAfterAccountPaginationSequence:(NSString *)accountPaginationSequence {

    //try1
    NSMutableDictionary *mutableQuery = [currentQuery mutableCopy];

    //try2 
    NSMutableDictionary *mutableQuery2=[NSMutableDictionary dictionaryWithDictionary:currentQuery];

    //crashes on this line
    mutableQuery[@"where"][@"account_pagination_sequence"] = @{ @"lt" : accountPaginationSequence };

    return mutableQuery;
}

Error Log (the app crashes on a limited amount of devices) 错误日志(应用在数量有限的设备上崩溃)

[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance

i think this is what you trying to achieve 我认为这是您想要实现的目标

+ (NSMutableDictionary *)updateQuery:(NSMutableDictionary *)currentQuery toSearchAfterAccountPaginationSequence:(NSString *)accountPaginationSequence {

    //try1
    NSMutableDictionary *mutableQuery = currentQuery.mutableCopy;
    NSMutableDictionary *where =  mutableQuery[@"where"].mutableCopy;

    where[@"account_pagination_sequence"] = @{ @"lt" : accountPaginationSequence };
    mutableQuery[@"where"] =  where;

    return mutableQuery;
}

Edit: In Objective-C calling mutableCopy on objects is not recursive.You need to call mutableCopy in nested objects too. 编辑:在Objective-C中,对对象调用mutableCopy不是递归的。您也需要在嵌套对象中调用mutableCopy。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [__NSDictionaryI setObject:forKey:]:无法识别的选择器已发送到实例 - [__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance [NSDictionaryI setObject:forKey:]: 无法识别的选择器发送到实例 - [NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance setObject:ForKey:崩溃? - setObject:ForKey: crash? -[__ NSDictionaryI setObject:forKey:]:无法识别的选择器已发送到实例0x91da0f0 - -[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x91da0f0 NSDictionaryM setObject:forKey:EXC_BAD_ACCESS崩溃 - NSDictionaryM setObject:forKey: EXC_BAD_ACCESS crash NSUserDefaults setObject:forKey死锁? - NSUserDefaults setObject:forKey deadlocks? 仅在iOS 9中,应用程序在[__NSCFDictionary setObject:forKey:]时崩溃 - App crashes at [__NSCFDictionary setObject:forKey:] in iOS 9 only setObject:forKey:和setValue:forKey:在NSMutableDictionary中的区别在哪里? - Where's the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary? setObject:forKey:发送给不可变对象的变异方法 - setObject:forKey: mutating method sent to immutable object NSMutableDictionary上的setObject:forKey:是否分配? - Does setObject:forKey: on NSMutableDictionary do an allocation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM