-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
完成KVStorage的dataBase和file部分 #29
Conversation
Sources/ClaretCache/KVStorage.swift
Outdated
#endif | ||
|
||
|
||
enum KVStorageType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否公开,不公开添加private, 公开添加public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在Swift中枚举应使用
enum KVStorageType {
case file
case sqlite
case mixed
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
|
||
extension UIApplication { | ||
static func isAppExtension() -> Bool { | ||
return IsAppExtension; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
|
||
import UIKit.UIApplication | ||
|
||
var IsAppExtension: Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是计算属性! 每次访问都会重新计算! 请用var isAppExtension: Bool = {xxx}()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外大小写
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
Sources/ClaretCache/KVStorage.swift
Outdated
} | ||
dbBindJoinedKeys(keys: keys, stmt: stmt, fromIndex: 1) | ||
var items: Array<KVStorageItem>? | ||
items = Array<KVStorageItem>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
定义和初始化可以写成为一句
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
@@ -0,0 +1,29 @@ | |||
// | |||
// UIApplication+CCAdd.swift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只是一个简单的extension,是否有添加一个文件的必要
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经删了文件
|
||
import UIKit.UIApplication | ||
|
||
var IsAppExtension: Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外大小写
Sources/ClaretCache/KVStorage.swift
Outdated
create index if not exists last_access_time_idx on manifest(last_access_time); | ||
*/ | ||
|
||
class KVStorage: NSObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
标明权限
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否一定要继承于NSObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
Sources/ClaretCache/KVStorage.swift
Outdated
#endif | ||
|
||
|
||
enum KVStorageType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在Swift中枚举应使用
enum KVStorageType {
case file
case sqlite
case mixed
}
Sources/ClaretCache/KVStorage.swift
Outdated
} | ||
|
||
deinit { | ||
#if os(iOS) && canImport(UIKit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
封装一下吧
Sources/ClaretCache/KVStorage.swift
Outdated
try fileMoveAllToTrash() | ||
fileEmptyTrashInBackground() | ||
} catch { | ||
print("reset error: \(error)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
添加一个log的方法,提供一个可以关闭的的选项
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
Sources/ClaretCache/KVStorage.swift
Outdated
} | ||
|
||
fileprivate func fileRead(fileName: String) throws -> Data? { | ||
return try Data.init(contentsOf: dataPath.appendingPathComponent(fileName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data(contentsOf: xxx)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
Sources/ClaretCache/KVStorage.swift
Outdated
trashPath = path.appendingPathComponent(kTrashDirectoryName) | ||
dbPath = path.appendingPathComponent(kDBFileName) | ||
do { | ||
try FileManager.default.createDirectory(at: path, withIntermediateDirectories: true, attributes: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
添加一个FileManager的属性
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
Sources/ClaretCache/KVStorage.swift
Outdated
dbStmtCache = nil | ||
repeat { | ||
retry = false | ||
let result = sqlite3_close(db!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不能使用强制解包
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
Sources/ClaretCache/KVStorage.swift
Outdated
fileprivate func dbJoinedKeys(_ keys: Array<Any>) -> String { | ||
var string = "" | ||
let max = keys.count | ||
for i in 0..<max { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
空格
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
Sources/ClaretCache/KVStorage.swift
Outdated
} | ||
|
||
deinit { | ||
#if os(iOS) && canImport(UIKit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处条件编译里没有任何语句?
let taskID = UIApplication.sharedExtensionApplication()?.beginBackgroundTask(expirationHandler: nil); | ||
dbClose() | ||
#if os(iOS) && canImport(UIKit) | ||
if let task = taskID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议:上面的taskID不需要单独定义,可简化为:if let taskId = UIApplication.sharedExtensionApplication()?.beginBackgroundTask(expirationHandler: nil)。
# Conflicts: # Sources/ClaretCache/MemoryCache.swift
Sources/ClaretCache/KVStorage.swift
Outdated
guard Bundle.main.bundleURL.pathExtension != "appex" else { | ||
return false | ||
} | ||
guard let app = NSClassFromString("UIApplication"), app.value(forKey: "shared") != nil else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guard let app = NSClassFromString("UIApplication"), app.value(forKey: "shared") != nil else 有没有纯swift方案呢?感觉这么写太oc了.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块还没进行测试呢,搞不好有问题,之前网上搜了一波,有些说要加bundle的名字,也不知道对不对
LGTM。 已完成初步修改,因disk开发需求,进行合并 |
CheckList
Thanks for considering to this repository. Before you submit your issue, please confirm these boxes are checked.
My issue:
What I have done: