Je continue à recevoir cette erreur lorsque j'exécute mon projet dans le simulateur. Cela se produit uniquement dans le simulateur xcode. Quand je lance le projet sur mon téléphone, il semble fonctionner parfaitement.Erreur CLLocationCoordinate2D lors de l'exécution dans Simulator Swift
Voici mon code suivant:
extension QuadTreeNode: AnnotationsContainer {
@discardableResult
func add(_ annotation: MKAnnotation) -> Bool {
guard rect.contains(annotation.coordinate) else { return false }
switch type {
case .leaf:
annotations.append(annotation)
// if the max capacity was reached, become an internal node
if annotations.count == QuadTreeNode.maxPointCapacity {
subdivide()
}
case .internal(let children):
// pass the point to one of the children
for child in children where child.add(annotation) {
return true
}
fatalError("rect.contains evaluted to true, but none of the children added the annotation")
}
return true
}
@discardableResult
func remove(_ annotation: MKAnnotation) -> Bool {
guard rect.contains(annotation.coordinate) else { return false }
_ = annotations.map { $0.coordinate }.index(of: annotation.coordinate).map { annotations.remove(at: $0) }
switch type {
case .leaf: break
case .internal(let children):
// pass the point to one of the children
for child in children where child.remove(annotation) {
return true
}
fatalError("rect.contains evaluted to true, but none of the children removed the annotation")
}
return true
}
private func subdivide() {
switch type {
case .leaf:
type = .internal(children: Children(parentNode: self))
case .internal:
preconditionFailure("Calling subdivide on an internal node")
}
}
func annotations(in rect: MKMapRect) -> [MKAnnotation] {
// if the node's rect and the given rect don't intersect, return an empty array,
// because there can't be any points that lie the node's (or its children's) rect and
// in the given rect
guard self.rect.intersects(rect) else { return [] }
var result = [MKAnnotation]()
// collect the node's points that lie in the rect
for annotation in annotations where rect.contains(annotation.coordinate) {
result.append(annotation)
}
switch type {
case .leaf: break
case .internal(let children):
// recursively add children's points that lie in the rect
for childNode in children {
result.append(contentsOf: childNode.annotations(in: rect))
}
}
return result
}
}
L'erreur semble se produire lorsque cette ligne est invoquée dans le code:
_ = annotations.map { $0.coordinate }.index(of: annotation.coordinate).map { annotations.remove(at: $0) }
L'erreur que je me lit: ne peut pas invoquer « index » avec liste d'arguments de type '(de: CLLocationCoodinate2D)'
Vous ne savez pas pourquoi je reçois cette erreur uniquement dans le simulateur.
Honnêtement, je ne sais pas, mais le simulateur peut-il utiliser CoreLocation? Je pense peut-être pas. – dfd
Oui, vous pouvez simuler l'emplacement en utilisant Xcode. La chose étrange est, cela me semble un message d'erreur de compilation et pas la description d'une erreur d'exécution ... –
Cela ne devrait pas fonctionner sur votre téléphone ou le simulateur puisque 'CLLocationCoordinate2D's ne sont pas 'Equatable' – dan