4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift:「Value of tuple type '(key: String, value: Any)' has no member 'subscript'」の対処方法

Last updated at Posted at 2018-07-07

はじめに

jsonをパースする際に発生した初歩的なエラーですが、直接的に解決できそうな記事がなく、初心者のため備忘録を含め記録として残したいと思います。

①Value of tuple type '(key: String, value: Any)' has no member 'subscript'について。

somethingWrong
if let results = data as? [String: Any] {
   for key in results {
       let data = key["downloadURL"] as [String:Any]
       }
   }
}

上記のようなコードでkeyがタプル型の場合に、発生するエラーのようです。
タプル型のため、以下のようなコードを記述すれば値が取得できるかと思います。

resolve
if let results = data as? [String: Any] {
   for key in results {
       print(key.key)
       print(key.value)
       }
   }
}

ご参考になれば幸いです。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?