Search code examples
objective-clldb

Error while setting object in NSMutableDictionary via lldb


While debugging I need to replace a value in the immutable dictionary. For that, I create a mutable dictionary from immutable and trying to set a value to this with lldb commands:

po NSMutableDictionary *$tmp = [(NSDictionary *) immutableDict mutableCopy]
po [$tmp setObject:@"object" forKey:@"key"]

But lldb fails with error:

error: cannot initialize a parameter of type 'id<NSCopying> _Nonnull' with an rvalue of type 'NSString *' passing argument to parameter 'aKey' here

Does anybody know how to fix that?


Solution

  • You should use this script:

    expression [mutableDict setValue:@"newObject" forKey:@"key"];
    

    this is setObject:forKey: definition:

    - (void)setObject:(ObjectType)anObject forKey:(KeyType <NSCopying>)aKey;
    

    the key should follow NSCopying protocol.

    and setValue:forKey: definition:

    - (void)setValue:(nullable ObjectType)value forKey:(NSString *)key;
    

    the key kind of class NSString.