读取时间戳,当模型类型为Firestore时间戳时,从SQLite数据库存储为Double

时间:2020-02-05 09:41:32

标签: swift sqlite google-cloud-firestore

我的模特:

init(dictionary: [String: Any]) {
....
    createdDate = dictionary["createdDate"] as? Timestamp <- FIRESTORE TIMESTAMP
....
    lastMessageDate = dictionary["lastMessageDate"] as? Timestamp <- FIRESTORE TIMESTAMP
....
}

我将数据保存在我的SQLite数据库中:

if sqlite3_prepare_v2(db, insertStatementString, -1, &insertStatement, nil) == SQLITE_OK {
.......
        sqlite3_bind_double(insertStatement, 4, createddate)
.......
        sqlite3_bind_double(insertStatement, 6, lastmessagedate)
.......

阅读:

let createdDate = sqlite3_column_double(queryStatement, 3)
....
            let createdDate = sqlite3_column_double(queryStatement, 3)
....
            let lastMessageDate = sqlite3_column_double(queryStatement, 5)
....             
            psns.append(ChatModel(dictionary: ["chatId": chatId, "partnerId": partnerId, "partnerName": partnerName, "createdDate": createdDate, "lastMessage": lastMessage, "lastMessageDate": lastMessageDate, "partnerProfileimage": partnerProfileImage]))

因此我的SQLite数据库中的Firestore时间戳类似于:1580329483.85847

在ViewController中,我正在将SQLite数据库中的数据加载到现有模型中。

现在,我正在尝试从SQLite数据库获取此日期(当我的模型期望使用TIMESTAMP时,我正在尝试获取一个DOUBLE。

for x in dbChats {
        print(x.lastMessageDate)
    }

但是x.lastMessageDate始终为零。如何将double值转换为预期的Firestore时间戳?

0 个答案:

没有答案
相关问题