배열을 반복하면서 좌표를 얻으 려하지만 오류가 발생하여 배열에 액세스 할 수 없습니다. 데이터는 seque를 통해 전달되고 인쇄되면 데이터가 올바르게 전송되므로 제대로 작동하지만 배열을 반복 할 수없고 위도와 경도를 가져올 수없는 이유가 해결되지 않습니다.배열 스위프트를 반복 할 때 오류가 발생했습니다.
이것은 콘솔의 출력입니다.
DeliveryDestinations (NameOrBusiness : 옵션 ("인앤 아웃 버거"), FirstLineAddress : 옵션 ("550 뉴홀 박사"), SecondLineAddress : 옵션 ("미국"), CityLineAddress : 옵션 (" 산호세 "), PostcodeLineAddress : 옵션 ("CA 95110 "), DistanceToDestination : 옵션 (9.2807823200000001), 위도 : 옵션 (37.350253606833043), 롱 : 옵션 (-121.92182779312132))
import UIKit
import MapKit
import CoreLocation
class DeliveryLocationsVC: UIViewController {
@IBOutlet weak var mapView: MKMapView!
var addressArr = [DeliveryDestinations]()
override func viewDidLoad() {
super.viewDidLoad()
print(addressArr)
navigationItem.title = "Delivery Location"
// Do any additional setup after loading the view.
for (theKey, theValue) in addressArr { //<-- error can't access the elements in array
if (theKey == "Lat") {
if let coordinates:DeliveryDestinations = theValue {
print (coordinates)
}
print("Item \(theKey): \(theValue)")
}
}
}
}
내 배열 fr에오고있다. 톰
import Foundation
import MapKit
struct DeliveryDestinations {
var NameOrBusiness: String?
var FirstLineAddress: String?
var SecondLineAddress: String?
var CityLineAddress: String?
var PostcodeLineAddress: String?
var DistanceToDestination: CLLocationDistance?
var Lat: Double?
var Long: Double?
init(NameOrBusiness: String?, FirstLineAddress: String?, SecondLineAddress: String?, CityLineAddress: String?, PostCodeLineAddress: String?, DistanceToDestination: CLLocationDistance?, Lat: Double?, Long: Double?) {
self.NameOrBusiness = NameOrBusiness
self.FirstLineAddress = FirstLineAddress
self.SecondLineAddress = SecondLineAddress
self.CityLineAddress = CityLineAddress
self.PostcodeLineAddress = PostCodeLineAddress
self.DistanceToDestination = DistanceToDestination
self.Lat = Lat
self.Long = Long
}
}
당신은 포함'theKey'와'theValue' 무엇을 기대합니까? – luk2302
@ luk2302 키가 위도 일 것이고 값은 키와 값이 같은 좌표가 될 것이며 값은 좌표가됩니다. 이 좌표를 기반으로 핀으로지도를 채울 수 있도록이 배열에 넣어보십시오. – QuickSilver
'theKey'가 왜 "Lat"이어야 하는가? 그건 말이 안돼요, 당신은 배열을 가지고 있습니다, 어디서나 찾을 수있는 "위도"가 없습니다. – luk2302