gpt4 book ai didi

ios - 字典中的自定义键

转载 作者:行者123 更新时间:2023-12-02 19:41:46 25 4
gpt4 key购买 nike

我想要实现的目标与我们使用 UIImagePickerControllerDelegate 的方法 imagePickerController(_:didFinishPickingMediaWithInfo:) 时所做的相同,其中我们可以访问 info 字典为

info[.originalImage]

我现在正在做的是这个

struct Foo {
var meta: [DictionaryKeys: Any]? = nil

struct DictionaryKeys: Hashable {
static let key1: DictionaryKeys // Error Here! I don't know what to put here
}
}

这会导致以下错误

'static var' declaration requires an initializer expression or getter/setter specifier

以及我最终想要如何访问它

let fooObject = Foo()
fooObject.meta[.key1] = "Some value"

并以同样的方式访问

最佳答案

您唯一需要做的就是创建枚举。这是代码

let fooObject = Foo()
fooObject.meta![.key1] = "Some Value"

struct Foo {
var meta: [DictionaryKeys: Any]? = nil

enum DictionaryKeys : String {
case key1
}
}

关于ios - 字典中的自定义键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59625824/

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