zoukankan      html  css  js  c++  java
  • 使用NSHashTable存储引用对象

    NSHashTable

          我们使用集合(NSArray,NSMutableArray,NSDictionary,NSMutableDictionary,NSSet,NSMutableSet)存储对象时会对其强引用(你可以使用单例的集合存储数据试一下咯),有时候我们不想这样子,怎么办呢?

          那就使用NSHashTable这个集合吧,它的使用方法与NSSet完全相似,不同的是,它的一种初始化方式是weakObjectsHashTable,专门用来存储弱引用对象,不会持有它,那个对象的所有人消失了,这个对象也会从这个集合中消失,多么人性化!

          下面介绍它的一些方法:

    - (BOOL)containsObject:(id)anObject

    Returns a Boolean value that indicates whether the hash table contains a given object.

    返回一个bool值,用来指示这个hash表中是否包括了你给与的对象.

    - (void)addObject:(id)object

    Adds a given object to the hash table.

    将一个对象添加进hash表中.

    - (void)removeObject:(id)object

    Removes a given object from the hash table.

    从hash表中移除你给定的对象.

    + (id)weakObjectsHashTable

    Returns a new hash table for storing weak references to its contents.

    返回一个hash表用来存储弱引用对象.

  • 相关阅读:
    有没有对象???new一个???
    原生数组的方法--翻转
    rclone的基本用法
    golang 文件操作
    记一次挖矿程序处理 firstpress
    python 第三方库 网络 requests
    python 第三方库 时间 arrow
    ansible playbook loop 翻译
    硬盘性能测试工具之bonnie++
    磁盘性能测试工具之fio
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3685927.html
Copyright © 2011-2022 走看看