IT story

Swift 3.0 통화 결과가 사용되지 않음

hot-time 2020. 6. 19. 07:59
반응형

Swift 3.0 통화 결과가 사용되지 않음


이 질문에는 이미 답변이 있습니다.

나는 스위프트 3.0으로 쓰고있다

이 코드를 사용하면 호출의 경고 결과가 사용되지 않습니다.

        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의 코드가 위에 오류가 발생합니다.

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

    }

나는 많은 방법을 시도했지만 작동하지 않지만 신속한 2.2에서는 이것이 왜 일어나는지 잘 알고 있습니다.


호출하는 함수가 값을 반환하지만 결과를 무시하기 때문에이 문제가 발생합니다.

이 문제를 해결하는 두 가지 방법이 있습니다.

  1. _ =함수 호출 앞에 추가하여 결과를 무시하십시오.

  2. @discardableResult컴파일러 선언을위한 함수 선언에 추가

참고URL : https://stackoverflow.com/questions/38192751/swift-3-0-result-of-call-is-unused

반응형