Kssss / ZQsafeObject

iOS 多线程安全的数组/字典/集合 类

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZQsafeObject

ZQsafeObject version 日期
iOS 1.0 2018-12

使用pod 导入

pod 'ZQsafeObject', '~> 1.0.0'

要求

iOS8.0 和Xcode 8以上

一、简介

在项目中使用到的数组/字典/集合一般都是单线程安全的。但是在多线程环境下是不安全的。通常给数据写入加锁。  
但是写起来会有一些麻烦。故将这些数组/字典/集合封装起来,更加面向对象。 
框架中使用信号量dispatch_semaphore_t做为线程控制,确保数据安全。使用和原生API类似。

二、使用

(1)数组

+ (instancetype)safetyArray;
+ (instancetype)safetyArrayWithArray:(NSArray *)array;
+ (instancetype)arrayWithCapacity:(NSUInteger)capacity;

(2)字典

+ (instancetype)safetyDictionary;
+ (instancetype)safetyDictionaryWithDictionary:(NSDictionary *)dict;
- (instancetype)initWithDictionary:(NSDictionary *)dict;

(3)set

+ (instancetype)safetySetWithSet:(NSSet *)set;
+ (instancetype)safetySetWithArray:(NSArray *)array;
- (instancetype)initWithArray:(NSArray *)array;
- (instancetype)initWithSet:(NSSet *)set;

About

iOS 多线程安全的数组/字典/集合 类


Languages

Language:Objective-C 97.1%Language:Ruby 2.9%