Hello,

To determine if a dictionary is mutable or Inmutable you just need to use the 
isKindOfClass method, instead of use respondsToSelector.

I did a test to reproduce your problem and couldn't reproduce your problem, so 
my conclusion is that actually you are receiving a mutable Dictionary when you 
think is unMutable 


I hope it helps you.


        NSDictionary                    *unmutableDictionary;
        NSMutableDictionary             *mutableDictionary;
        NSDictionary                    *testDictionary;
        Class                                   ummutableClass;
        Class                                   mutableClass;
        
        ummutableClass = [NSDictionary  class];
        mutableClass = [NSMutableDictionary class];
        
        unmutableDictionary = [NSDictionary dictionary];
        mutableDictionary       = [NSMutableDictionary  dictionary];
        
        /**
         To test the situation where the function input parameter is a 
NSDictionary and be able
         to detect if the passed object is mutable or unmutable we use the 
testDictionary as "input parameter"
         */
        
        
        /**
         An Inmutable dictionary shoud only be Inmutable Class
         */
        //TEST Inmutable Dictionary
        testDictionary = unmutableDictionary;
        if ([testDictionary isKindOfClass: ummutableClass] == YES) {
                NSLog(@"Test %d.%@ OK", 1,@"A");
        } else {
                NSLog (@"Test %d.%@ ERROR", 1,@"A");
        }

        if ([testDictionary isKindOfClass: mutableClass] == NO) {
                NSLog(@"Test %d.%@ OK", 1,@"B");
        } else {
                NSLog (@"Test %d.%@ ERROR", 1,@"B");
        }
        
        if ([testDictionary respondsToSelector:@selector(setObject:forKey:)] == 
NO) {
                NSLog(@"Test %d.%@ OK", 1,@"C");
        } else {
                NSLog (@"Test %d.%@ ERROR", 1,@"C");
        }
        
        /**
         A Mutable dictionary shoud be from both classes (Mutable and inmutable)
         */     
        //Test Mutable Dictionary
        testDictionary = mutableDictionary;
        if ([testDictionary isKindOfClass: ummutableClass] == YES) {
                NSLog(@"Test %d.%@ OK", 2,@"A");
        } else {
                NSLog (@"Test %d.%@ ERROR", 2,@"A");
        }
        
        if ([testDictionary isKindOfClass: mutableClass] == YES) {
                NSLog(@"Test %d.%@ OK", 2,@"B");
        } else {
                NSLog (@"Test %d.%@ ERROR", 2,@"B");
        }
        
        if ([testDictionary respondsToSelector:@selector(setObject:forKey:)] == 
YES) {
                NSLog(@"Test %d.%@ OK", 2,@"C");
        } else {
                NSLog (@"Test %d.%@ ERROR", 2,@"C");
        }


OUTPUT:

2011-01-14 12:31:31.970 Dictionary TEST[2672:207] Test 1.A OK
2011-01-14 12:31:31.972 Dictionary TEST[2672:207] Test 1.B OK
2011-01-14 12:31:31.973 Dictionary TEST[2672:207] Test 1.C OK
2011-01-14 12:31:31.988 Dictionary TEST[2672:207] Test 2.A OK
2011-01-14 12:31:31.994 Dictionary TEST[2672:207] Test 2.B OK
2011-01-14 12:31:31.994 Dictionary TEST[2672:207] Test 2.C 
OK_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to