Swift:如何在字符串表达式中打印出字典键的值?

Swift:如何在字符串表达式中打印出字典键的值?,第1张

概述参见英文答案 > escape dictionary key double quotes when doing println dictionary item in Swift                                    5个 出于某种原因,我只是不能使这个表达式工作: let expandedBio: Dictionary<String,AnyObject> = ["n @H_403_0@ @H_403_0@ 参见英文答案 > escape dictionary key double quotes when doing println dictionary item in Swift                                    5个
出于某种原因,我只是不能使这个表达式工作:

let expandedBio: Dictionary<String,AnyObject> = ["name":"Saurabh","profession":"developer","language":"java","employed": true]if let employed : AnyObject = expandedBio["employed"] {    println("\(expandedBio[\"name\"]) is not available")}

如何输出println语句?我收到了错误

Unexpected "" character  error in string interpolation

我该怎么做?

解决方法 在当前版本的Swift中,您必须先将值放在自己的常量/变量中,然后使用它.

if let employed : AnyObject = expandedBio["employed"] {    let t = expandedBio["name"]    println("\(t) is not available")}
@H_403_0@ 总结

以上是内存溢出为你收集整理的Swift:如何在字符串表达式中打印出字典键的值?全部内容,希望文章能够帮你解决Swift:如何在字符串表达式中打印出字典键的值?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004475.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存