GrandStore
GrandStore是一个直观且强大的iOS存储库,他用变量名来保存任何类型
关键特点
- GrandStore是基于泛型类的,因此它可以存储任何符合NSCoding协议的Object。
- 可以任意存值和取值
- 强大的缓存特性
- 存储的值可以被观察,只要您调用了addObserver函数。
- 清除缓存也很简单
系统要求
Xcode 8 和 iOS 8.0(最新的Swift语法,Swift3) ####请注意,这个类仅适用于纯Swift项目,ObjC类不能调用这个类 ##安装 如果你使用cocopods, 则pod 'GrandStore' 再安装即可.然后再 pod install
如果您想使用文件,直接将GrandStore.swift复制到您的项目中即可
如何使用
*请参考以下代码
var demoText = GrandStore(name: "DemoText", defaultValue: ""), the second para can not be nil, GrandStore must usr it to infer the type.
demoText.Value = "the value you will set" //set the value
let va = demoText.Value //get the value
let stu = GrandStore(name: "student", defaultValue: Student())// Student is a custom cass and it must confirm NSCoding protocal.The set and get process is the same as the DemoText
var demoCache = GrandStore(name: "CacheTest", defaultValue: "", timeout: 10)//if you want set a value which can expire,just add the timeout para. cache time
demoCache..setCacheTime(50)// you can change the cache time anytime, or you can set a current GrandStore to cache mode
demoCache.clear()// call the clear() func to clear the cache
stu.addObserver { (observerObject, observerKey, oldValue, newValue) -> Void in
self.lblStudent?.text = "old:\(oldValue.debugDescription), new:\(newValue.debugDescription)"
}
//if you want to observer the value change, just call the addObserver func, and set the block callback
stu.removeObserver() //call the removeObserver() func to remoce the observer
*参考GrandStoreDemo将更好地理解GrandStore的使用方法
和我联系
有任何问题或者BUG请直接和我联系[邮箱地址加密显示],我会乐于帮你解决