How to Use nsmutabledictionary

Source: Internet
Author: User

The dictionary and the array and string also have a variable subclass, but the method names involved are different, but the principles are similar.

 

Methods involved:

Removeobjectforkey:Delete a specified key-Value Pair (PS: only the key is entered here. The key and value are deleted, but nothing happens to the input value ).

 

Let's take a look at the example below:

#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) {    @autoreleasepool {        NSMutableDictionary *dicti = [NSMutableDictionary new];        [dicti setObject:@"Five" forKey:@"5"];        [dicti setObject:@"Four" forKey:@"4"]; //添加指定的键值对//        [dicti setObject:@"Five" forKey:@"5"];        //添加键值对和删除键值对的时候没有说是插入到哪里, 和删除哪一个, 因为字典中的键值对是不讲究位置的.        NSLog(@"dicti = %@", dicti);                        //removeObjectForKey:删除对应的键值对.        //删除键值对也是同样不将就顺序.//        [dicti removeObjectForKey:@"4"];        [dicti removeObjectForKey:@"5"];        NSLog(@"diciti = %@", dicti);                [dicti release];    }    return 0;}

Output result:

2014-10-13 21:16:31.843 NSMutableDictionary[6749:303] dicti = {    4 = Four;    5 = Five;}2014-10-13 21:16:31.844 NSMutableDictionary[6749:303] diciti = {    4 = Four;}Program ended with exit code: 0

 

How to Use nsmutabledictionary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.