반응형
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에서는 이것이 왜 일어나는지 잘 알고 있습니다.
호출하는 함수가 값을 반환하지만 결과를 무시하기 때문에이 문제가 발생합니다.
이 문제를 해결하는 두 가지 방법이 있습니다.
_ =
함수 호출 앞에 추가하여 결과를 무시하십시오.@discardableResult
컴파일러 선언을위한 함수 선언에 추가
참고URL : https://stackoverflow.com/questions/38192751/swift-3-0-result-of-call-is-unused
반응형
'IT story' 카테고리의 다른 글
배경 크기 시뮬레이션 : 커버 (0) | 2020.06.19 |
---|---|
double이 정수인지 테스트하는 방법 (0) | 2020.06.19 |
git 저장소에서 병합 한 후 .orig 파일을 삭제하는 방법은 무엇입니까? (0) | 2020.06.19 |
SQL Server Reporting Services 보고서에 대체 행 색 추가 (0) | 2020.06.19 |
RSpec을 사용하여 JSON 응답을 확인하는 방법은 무엇입니까? (0) | 2020.06.19 |