This question already has an answer here:
这个问题已经有了答案:
- Xcode 8 / Swift 3: “Expression of type UIViewController? is unused” warning 7 answers
- Xcode 8 / Swift 3:“UIViewController的表达式?”未使用的“警告7答案?
I am writing in swift 3.0
我用的是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
我曾在其他类中尝试过使用这个方法,但它仍然给出了上面的insertAnnotation代码的错误
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??
我尝试过很多方法,但都没有用,但是在swift 2.2中,它很好用,你知道为什么会这样吗?
1 个解决方案
#1
332
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将@discardableResult添加到函数的声明中,以使编译器静默。
#1
332
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将@discardableResult添加到函数的声明中,以使编译器静默。