gpt4 book ai didi

ios - 无法将 Bool 类型的值分配给类型 String 数据库表示

转载 作者:行者123 更新时间:2023-12-01 18:35:14 26 4
gpt4 key购买 nike

如何将非字符串类型的数据添加到 DatabaseRepresentation。我尝试过 AnyObject,但不符合哈希协议(protocol)。

lastMessageRead 是 Bool 类型还是我只是将其存储为字符串?

extension Channel: DatabaseRepresentation {

var representation: [String : Any] {
var rep = ["ownerName": ownerName]
rep["ownerId"] = ownerId
rep["participantName"] = participantName
rep["participantId"] = participantId
rep["lastMessage"] = lastMessage
rep["lastMessageId"] = lastMessageId

if let lastMessageRead = lastMessageRead {
rep["lastMessageRead"] = lastMessageRead **Cannot assign Bool to String
}

if let id = id {
rep["id"] = id
}
return rep
}
}

最佳答案

你可以试试这个:

var representation: [String : String]

rep["yourData"] = "\(your data)"

对于日期:
    let formatter = DateFormatter()
formatter.dateStyle = DateFormatter.Style.medium
formatter.timeStyle = DateFormatter.Style.none
formatter.dateFormat = "dd.MM.yyyy"
let text = formatter.string(from: yourDateValue)
rep["yourDate"] = text

希望能帮助到你...

关于ios - 无法将 Bool 类型的值分配给类型 String 数据库表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60541174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com