Xcode 8 and 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请直接和我联系[email protected], 我会乐于帮你解决
link |
Stars: 4 |
Last commit: 2 years ago |
替换原先的GrandCache,换成MMKV使用效果更好
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics