zoukankan      html  css  js  c++  java
  • OC之【NSMutableDictionary的使用】

    main.m文件

    #import <Foundation/Foundation.h>

    #import "Student.h"

    #pragma mark 可变字典的使用

    void dictUse() {

        //创建一个空的字典

        NSMutableDictionary *dict = [NSMutableDictionarydictionary];

       Student *stu1 = [StudentstudentWithName:@"stu1"];

       Student *stu2= [StudentstudentWithName:@"stu2"];

        

        // 添加元素

        // stu1的计数器会+1

        [dictsetObject:stu1 forKey:@"k1"];

       NSLog(@"stu1:%zi", [stu1retainCount]);

        

        // 添加其他字典other到当前字典dict中

        NSDictionary *other = [NSDictionarydictionaryWithObject:@"v2"forKey:@"k2"];

        [dict addEntriesFromDictionary:other];

        

        //删除所有的键值对

        // [dict removeAllObjects];

        

        // 删除k1对应的元素stu1,stu1会做一次release操作

        [dict removeObjectForKey:@"k1"];

       NSLog(@"stu1:%zi", [stu1retainCount]);

        

        // 删除多个key对应的value

        // [dict removeObjectsForKeys:[NSArray arrayWithObject:@"k1"]];

        

        // 字典被销毁时,内部的所有key和value计数器都会-1,也就是说stu1会release一次

    }

    int main(int argc,const char * argv[])

    {

        @autoreleasepool {

           dictUse();

        }

       return 0;

    }

    On the road。。。
  • 相关阅读:
    斗鱼扩展--localStorage备份与导出(九)
    斗鱼扩展--管理移除房间(八)
    斗鱼扩展--让你看到更多内容(七)
    Ubuntu18.04 安装水星1300M无线网卡
    Course1_Week1_ProgrammingHomeWork
    找出3个数中不为-1的最小数
    马拉车算法
    偏差-方差分解
    决策树如何防止过拟合
    可视化数据集两个类别变量的关系
  • 原文地址:https://www.cnblogs.com/ianhao/p/4426123.html
Copyright © 2011-2022 走看看