首页 > 解决方案 > 存储使用不清楚

问题描述

如何在 Vapor 4 中使用存储?

我尝试了以下方法:

if let someValue = req.storage.get(theKey) as? String {
    // do something
} else {
    req.storage.set(theKey, to: "Some Value")
}

但是我收到以下错误:

error: type of expression is ambiguous without more context
    if let original: String = req.storage.get(theKey) {
                              ~~~~~~~~~~~~^~~~~~~~~~~
error: type of expression is ambiguous without more context
    req.storage.set(theKey, to: "Some Value")
    ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

我也没有找到有关此主题的任何文档。

标签: vapor

解决方案


Key 不可能是任意字符串。密钥必须是预定义的。


推荐阅读