Ary*_*yap 143 ios swift swift3
我在swift 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()
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试在另一个类中使用此方法,但它仍然给我错误,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
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多方法,但只是不起作用,但在swift 2.2它可以正常任何想法为什么会发生这种情况?
Dav*_*ndz 440
您遇到此问题,因为您正在调用的函数返回一个值,但您忽略了结果.
有两种方法可以解决此问题:
通过_ =在函数调用前添加来忽略结果
添加@discardableResult到函数的声明以使编译器静音
| 归档时间: |
|
| 查看次数: |
58425 次 |
| 最近记录: |