주석간에 스 와이프 할 수있는 tvOS 앱에서 작업하고 있습니다. 사전에 주석을 저장하고 나중에 사용할 수 있도록 사전에 배열을 저장합니다. 저는 캐나다, 미국 및 멕시코에 대한 세 가지 주석을 단순히 그려 둡니다. 이 주석 사이에서 리모컨을 스 와이프하고 싶습니다. 주석을 클릭하면 해당 국가에 대한 정보로 이동합니다. 세 나라가 그려되면이진 연산자 '=='은 '[MKAnnotation]'및 'MKAnnotation'유형의 피연산자에 적용 할 수 없습니다.
let countriesArray = ["Canada", "Mexico", "United States of America"]
var annotationArray = [MKPointAnnotation]()
var locationDictionary = [String: AnyObject]()
var locationArray = [AnyObject]()
, 내 배열처럼 보이는 다음 : 애플 리모트가 swipped 때
locationArray [{
annotation = "<MKPointAnnotation: 0x7fc021b01f70>";
country = Canada;
latitude = "71.47385399229037";
longitude = "-96.81064609999999";
}, {
annotation = "<MKPointAnnotation: 0x7fc0219dcf90>";
country = "United States of America";
latitude = "37.99472997055178";
longitude = "-95.85629150000001";
}, {
annotation = "<MKPointAnnotation: 0x7fc02260ff70>";
country = Mexico;
latitude = "23.94480686844645";
longitude = "-102.55803745";
}]
가, 아래로, 예를 들어, 내가 만약에 다음과 같은 오류를 받고 있어요 아래 조건.
이진 연산자 "== '형식의 피연산자'[MKAnnotation] '를 적용 할 수 없습니다'MKAnnotation '
I가 하나로 arrary에서 주석과 비교 어떻게 선택?
func swipedDown(sender:UISwipeGestureRecognizer) {
print("Down")
let selectedAnnotation = mapView.selectedAnnotations
for x in 0 ... locationArray.count - 1 {
let value = locationArray[x].valueForKey("annotation") as! MKAnnotation
if selectedAnnotation == value { //error
let currentLocation = locationArray[x].valueForKey("country")
print("Your on \(currentLocation)")
}
}
}
답변 해 주셔서 감사합니다. 귀하의 제안은 다음을 던졌습니다 : 'MKAnnotation'유형의 값을 예상 인수 유형 '@noescape (MKAnnotation) throws -> Bool'' –
@PaulS로 변환 할 수 없습니다. 이것은 매우 이상합니다. 스위프트의 어떤 버전을 사용하고 있습니까? – dasblinkenlight
contains의 non-closure 버전은'MKAnnotation'이 아닌'Equatable' 요소를 필요로하기 때문입니다. – dan