I know I am so late in answering this question and one answer is already accepted, but still to help someone.
Sometime converting swift dictionary ([String : String] or [AnyHashable : String] or any other) to Objective-C NSMutableDictionary, if there are some nested objects like array or dictionaries within that will not get mutable as so when updating the values will get error of [NSDictionaryI setObject:forKey:]: unrecognised selector sent to instance
To prevent this error one can convert the object in objective-c class.
In my case I am converting a JSON string into swift dictionary and passing it to objective c class by casting it in NSMutableDictionary as per my core requirement. This gives me an above error when I try to update the NSMutableDictionary in Objective C class.
After surfing and trying much I found that if I try to convert my JSON string in NSMutableDictionary in Objective-C class itself than it worked for me.
So try this: In aVC.swift
let Str: String = nsmanagedobject.value(forKey: "<key>") as? String {
if let mutableDict: NSMutableDictionary = ApplicationData.convertJsonObject(fromJsonString: Str) as? NSMutableDictionary {
......
<Your code to pass NSMutableDictionary to respected Objective-C class>
......
}
ApplicationData.h
+ (NSObject *)convertJsonObjectFromJsonString:(NSString *)jsonString;
ApplicationData.m
+ (NSObject *)convertJsonObjectFromJsonString:(NSString *)jsonString {
NSObject *jsonObject = nil;
if ([jsonString length] > 0) {
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
if (jsonData) {
jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
}
}
NSLog(@"jsonObject: %@",jsonObject);
return jsonObject;
}
I hope this will help someone and save some time.