BUPersistence.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // BUPersistence.h
  3. // BUPersistence
  4. //
  5. // Created by Chen Hong on 2017/1/10.
  6. // Copyright © 2017年 Chen Hong. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. typedef NS_ENUM(NSUInteger, BUPersistentType) {
  11. BUPersistentTypePlist,
  12. BUPersistentTypeKeyChain,
  13. BUPersistentTypeCustom,
  14. };
  15. @interface BUPersistenceOption : NSObject
  16. @property (nonatomic) BUPersistentType type;
  17. @property (nonatomic) BOOL shouldRemoveAllObjectsOnMemoryWarning;
  18. @property (nonatomic) BOOL shouldRemoveAllObjectsWhenEnteringBackground;
  19. @property (nonatomic) BOOL supportNSCoding;
  20. @end
  21. @protocol BUPersistenceProtocol <NSObject>
  22. - (NSArray *)allObjects;
  23. - (nullable id)objectForKey:(NSString *)key;
  24. - (nullable NSArray *)objectsForKeys:(NSArray *)keys;
  25. - (void)updateObjectsForKeys:(NSArray *)keys WithBlock:(NSDictionary * (^)(NSArray *objects))block;
  26. - (BOOL)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key;
  27. - (BOOL)hasObjectForKey:(NSString *)key;
  28. - (BOOL)removeAll;
  29. - (BOOL)removeObjectsForKeys:(NSArray<NSString *> *)keys;
  30. - (BOOL)save;
  31. @end
  32. @interface BUPersistence : NSObject <BUPersistenceProtocol>
  33. + (nullable instancetype)persistenceWithName:(NSString *)name;
  34. + (nullable instancetype)persistenceWithName:(NSString *)name option:(BUPersistenceOption *)option;
  35. + (void)deleteWithName:(NSString *)name;
  36. + (NSString *)cacheDirectory;
  37. @end
  38. NS_ASSUME_NONNULL_END