2
'결과 '가'결과 '배열의 객체를 나타내는 것이 목적이라면 case let
을 다음과 같이 드롭하고'for result in '을 사용하십시오. 왜 case let
이 필요한지 이해할 수 없습니다.Swift syntax 'case for for 루프가 혼란 스럽습니다.
if let data = data, let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
for case let result in json["results"] {
if let restaurant = Restaurant(json: result) {
restaurants.append(restaurant)
}
}
}
JSON
{
"query": "sandwich",
"results_count": 12,
"page": 1,
"results": [
{
"name": "Caffè Macs",
"coordinates": {
"lat": 37.330576,
"lng": -122.029739
},
"meals": ["breakfast", "lunch", "dinner"]
},
...
]
}
REF : https://developer.apple.com/swift/blog/ 당신이 원하는 경우, results
응답의 모든 오브젝트를 원하기 때문에 루프와 case let
를 사용할 필요가 없습니다 귀하의 경우에는