Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

はじめに

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)
       }
   }
}

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

Atsushi_
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away