简体   繁体   中英

__NSDictionaryI setObject:forKey: Crash

The problem is that I am mutating a NSDictionary , but even after getting a mutableCopy , the app crashes.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM