【发布时间】:2019-01-13 22:24:53
【问题描述】:
我有一个混合类型(字符串、NSImage 和数组)的字典。附加到数组时,出现错误“'Any??' 类型的值没有成员'追加'”。我看不到如何将“file_list”值转换为数组,因此我可以将值附加到它。
var dataDict: [String:Any?] = [
"data_id" : someString,
"thumbnail" : nil,
"file_list" : [],
]
// do stuff... find files... whirrr wizzzz
dataDict["thumbnail"] = NSImage(byReferencingFile: someFile)
dataDict["file_list"].append( someFile ) <- ERROR: Value of type 'Any??' has no member 'append'
【问题讨论】:
-
你为什么不使用像
struct DataDict {var dataId: String; var thumbname: NSImage?; var fileList: [String]}这样的结构?
标签: swift dictionary types