Skip to content
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

Merged
merged 11 commits into from
Jul 31, 2019

Conversation

Ekulelu
Copy link

@Ekulelu Ekulelu commented Jul 29, 2019

CheckList

Thanks for considering to this repository. Before you submit your issue, please confirm these boxes are checked.

  • I have read 《[EN]Style guide for Swift repo [CN]Swift项目代码规范、规约选型》.
  • 我遵守一下 Merge 规则:邀请群组中任意一人进行review,即可合并。让 reviewer 在 PR 所在页面写下review意见表示通过,即可合并。最简单写一句 LGTM 也可以。不按照本规则执行,自己 PR 自己 Merge 并引入问题,会被收回 Merge 权限。

My issue:


What I have done:

#endif


enum KVStorageType {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否公开,不公开添加private, 公开添加public

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
}

Copy link
Author

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

格式!

Copy link
Author

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是计算属性! 每次访问都会重新计算! 请用var isAppExtension: Bool = {xxx}()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外大小写

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

}
dbBindJoinedKeys(keys: keys, stmt: stmt, fromIndex: 1)
var items: Array<KVStorageItem>?
items = Array<KVStorageItem>()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

定义和初始化可以写成为一句

Copy link
Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只是一个简单的extension,是否有添加一个文件的必要

Copy link
Author

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外大小写

create index if not exists last_access_time_idx on manifest(last_access_time);
*/

class KVStorage: NSObject {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

标明权限

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否一定要继承于NSObject

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

#endif


enum KVStorageType {

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
}

}

deinit {
#if os(iOS) && canImport(UIKit)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

封装一下吧

try fileMoveAllToTrash()
fileEmptyTrashInBackground()
} catch {
print("reset error: \(error)")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加一个log的方法,提供一个可以关闭的的选项

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

}

fileprivate func fileRead(fileName: String) throws -> Data? {
return try Data.init(contentsOf: dataPath.appendingPathComponent(fileName))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data(contentsOf: xxx)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

trashPath = path.appendingPathComponent(kTrashDirectoryName)
dbPath = path.appendingPathComponent(kDBFileName)
do {
try FileManager.default.createDirectory(at: path, withIntermediateDirectories: true, attributes: nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加一个FileManager的属性

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

dbStmtCache = nil
repeat {
retry = false
let result = sqlite3_close(db!)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能使用强制解包

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

fileprivate func dbJoinedKeys(_ keys: Array<Any>) -> String {
var string = ""
let max = keys.count
for i in 0..<max {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

空格

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

}

deinit {
#if os(iOS) && canImport(UIKit)
Copy link

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 {
Copy link

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)。

@Ekulelu Ekulelu closed this Jul 30, 2019
@Ekulelu Ekulelu reopened this Jul 30, 2019
guard Bundle.main.bundleURL.pathExtension != "appex" else {
return false
}
guard let app = NSClassFromString("UIApplication"), app.value(forKey: "shared") != nil else {

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了.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块还没进行测试呢,搞不好有问题,之前网上搜了一波,有些说要加bundle的名字,也不知道对不对

@birdmichael
Copy link
Member

LGTM。 已完成初步修改,因disk开发需求,进行合并

@birdmichael birdmichael merged commit 2448007 into iteatimeteam:develop Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants