I am writing in swift 3.0
i have this code which gives me the warning result of call is unused
public override init(){
super.init()
}
public init(annotations: [MKAnnotation]){
super.init()
addAnnotations(annotations: annotations)
}
public func setAnnotations(annotations:[MKAnnotation]){
tree = nil
addAnnotations(annotations: annotations)
}
public func addAnnotations(annotations:[MKAnnotation]){
if tree == nil {
tree = AKQuadTree()
}
lock.lock()
for annotation in annotations {
// The warning occurs at this line
tree!.insertAnnotation(annotation: annotation)
}
lock.unlock()
}
i have tried using this method in another classes but it still gives me the error the code for insertAnnotation is above
func insertAnnotation(annotation:MKAnnotation) -> Bool {
return insertAnnotation(annotation: annotation, toNode:rootNode!)
}
func insertAnnotation(annotation:MKAnnotation, toNode node:AKQuadTreeNode) -> Bool {
if !AKQuadTreeNode.AKBoundingBoxContainsCoordinate(box: node.boundingBox!, coordinate: annotation.coordinate) {
return false
}
if node.count < nodeCapacity {
node.annotations.append(annotation)
node.count += 1
return true
}
if node.isLeaf() {
node.subdivide()
}
if insertAnnotation(annotation: annotation, toNode:node.northEast!) {
return true
}
if insertAnnotation(annotation: annotation, toNode:node.northWest!) {
return true
}
if insertAnnotation(annotation: annotation, toNode:node.southEast!) {
return true
}
if insertAnnotation(annotation: annotation, toNode:node.southWest!) {
return true
}
return false
}
i have tried many methods but just doesn't work but in swift 2.2 it works fine any ideas why this is happening??
You are getting this issue because the function you are calling returns a value but you are ignoring the result.
There are two ways to solve this issue:
Ignore the result by adding _ =
in front of the function call
Add @discardableResult
to the declaration of the function to silence the compiler