Swift 3.0呼叫结果未使用 [英] Swift 3.0 Result of call is unused

查看:109
本文介绍了Swift 3.0呼叫结果未使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在swift 3.0中写作

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()
        }

我试过在另一个类中使用此方法但它仍然给出错误,insertAnnotation的代码高于

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

    }



<我已经尝试了很多方法,但只是不起作用,但在swift 2.2中它可以解决为什么会发生这种情况?

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:


  1. 通过添加 _ = 忽略结果函数调用前面

  1. Ignore the result by adding _ = in front of the function call

@discardableResult 添加到函数声明中以使编译器静音

Add @discardableResult to the declaration of the function to silence the compiler

这篇关于Swift 3.0呼叫结果未使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆