vapor - 存储使用不清楚
问题描述
如何在 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")
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我也没有找到有关此主题的任何文档。
解决方案
Key 不可能是任意字符串。密钥必须是预定义的。
推荐阅读
- java - 如何用简单的方式重写一个黄瓜场景?
- python - 在 SciPy 中进行 Delauny 三角剖分后,我如何获得面和顶点?
- javascript - 在下拉菜单中将子列表项与父项对齐
- java - 如何修复 no javabridge no module 错误?如何查找和设置jdk路径?
- java - 退出方法/进程而不调用 exit() 方法
- r - 在 Rstudio 中保存 R 脚本
- node.js - 如何修复 Windows 10 中的“rimraf 不是可识别的命令”
- c# - 如何将 CanvasBitmap.CreateFromBytes 与来自 jpg 图像的字节 [] 一起使用
- android - “Xbox Button”的 Android keyEvent 键码
- c# - 如何将动态格式传递给 C# 6 插值字符串