Swift:上下文类型"AnyObject"不能与字典文字一起使用 [英] Swift: Contextual type 'AnyObject' cannot be used with dictionary literal

查看:86
本文介绍了Swift:上下文类型"AnyObject"不能与字典文字一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构建这本词典时遇到困难.我的代码如下:

I am having difficulty constructing this dictionary. My code looks like this:

var array: [String] = []
let params: [String: AnyObject] = [
    "presentation": [
            "array": array,
            "current_index": 0
    ]
]

错误显示在第一行"presentation": [中,且上下文类型'AnyObject'无法与字典文字一起使用.我试图重写数组,初始化参数,然后设置值,等等.任何帮助都会很棒!

The error shows up on the first line "presentation": [ with Contextual type 'AnyObject' cannot be used with dictionary literal. I have tried rewriting the array, initializing the params then setting the values, etc. etc. and I cannot figure out this problem. Any help would be awesome!

提前谢谢!

推荐答案

尝试一下

let params: [String: [String: AnyObject]]

并在current_index键后关闭引号.

这篇关于Swift:上下文类型"AnyObject"不能与字典文字一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆