Four dictionaries of Data Types in objective-C (nsdictionary)

Source: Internet
Author: User

// 1. 字典初始化、赋值方式1    NSMutableDictionary *m_dictionary = [[NSMutableDictionary alloc] initWithCapacity:0];    [m_dictionary setObject:@1 forKey:@"语文"];    [m_dictionary setObject:@2 forKey:@"数学"];    [m_dictionary setObject:@3 forKey:@"英语"];    // 字典初始化、赋值方式2    NSDictionary *dict1 = @{@"语文": @1, @"数学": @2, @"英语": @3};    m_dictionary = [NSMutableDictionary dictionaryWithDictionary:dict1];        // 字典初始化、赋值方式3    m_dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: @1, @"语文", @2, @"数学", @3, @"英语", nil];    // 字典初始化、赋值方式4    m_dictionary = [NSMutableDictionary dictionaryWithObjects:@[@1, @2, @3] forKeys:@[@"语文", @"数学", @"英语"]];    // 赋值方式5    NSDictionary *dict2 = @{ @"物理": @4};    [m_dictionary addEntriesFromDictionary:dict2];        // 2. 排序 方式1    NSArray *sortedKeysArray =    [m_dictionary keysSortedByValueUsingSelector:@selector(compare:)];    // sortedKeysArray (语文, 数学, 英语, 物理)    // 方式2    NSArray *blockSortedKeys = [m_dictionary keysSortedByValueUsingComparator: ^(id obj1, id obj2) {        return [obj1 compare:obj2];    }];    // blockSortedKeys (语文, 数学, 英语, 物理)

Four dictionaries of Data Types in objective-C (nsdictionary)

Related Article

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.