首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Swift 3.0调用结果未使用

Swift 3.0调用结果未使用
EN

Stack Overflow用户
提问于 2016-07-05 06:04:36
回答 1查看 85.9K关注 0票数 166

我正在用swift 3.0写文章

我有这个代码,它告诉我调用的警告结果是未使用

代码语言:javascript
复制
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()
}

我曾尝试在另一个类中使用此方法,但它仍然显示错误insert Annotation的代码在上面

代码语言:javascript
复制
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
}

我尝试了许多方法,但都不起作用,但在swift 2.2中,它工作得很好,你知道为什么会发生这种情况吗?

EN

回答 1

Stack Overflow用户

发布于 2016-07-05 08:15:48

你得到这个问题是因为你调用的函数返回一个值,但是你忽略了结果。

有两种方法可以解决这个问题:

  1. 忽略结果,方法是在函数调用前面添加_ =
  2. @discardableResult添加到函数的声明中,以使编译器

静默

票数 535
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38192751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档