【问题标题】:Copy local dictionary into global dictionary将本地字典复制到全局字典中
【发布时间】:2016-11-16 06:20:55
【问题描述】:

我有一个问题,我在一个方法中创建一个字典,然后尝试使一个字段等于字典!

所以:

var theJson : NSDictionary!

func someMethod()
{
   if let theDictionary = valueFromGoogleDirections as? NSDictionary
   theJson = theDictionary
}

func fieldTest()
{
   print(theJson)
}

在调用 someMethod 然后 fieldTest 之后 fieldTest 方法总是打印“{ }”,我认为这意味着它是一个空字典。到底是怎么回事?我知道字典正在获取值,因为我可以在 someMethod 方法中使用它的值。

【问题讨论】:

  • someMethod 是否进行了异步调用?如果是,则需要使用完成块。
  • 我不相信,但我会调查一下。谢谢!

标签: json swift xcode dictionary google-directions-api


【解决方案1】:

试试这个:

theJson = theDictionary.copy()

【讨论】:

    猜你喜欢
    • 2013-11-15
    • 2011-11-19
    • 2013-01-24
    • 1970-01-01
    • 2021-05-06
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    相关资源
    最近更新 更多