相关疑难解决方法(0)

Swift 3.0呼叫结果未使用

我在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 …
Run Code Online (Sandbox Code Playgroud)

ios swift swift3

143
推荐指数
1
解决办法
6万
查看次数

键入时关闭Xcode未使用的变量警告

在打字的时候,我厌倦了Xcode多次使用现场"未使用的变量"警告.我一直在想我的语法错误,停止我正在做的事情,检查警告,只看到它是一个未使用的变量警告.

在此输入图像描述

当然它没用,我只是输入它!

我不介意编译时未使用的变量警告,这些非常有用,但我讨厌实时警告,因为我正在键入代码.

有没有办法可以在任何地方完全关闭此警告,无论是应用程序范围还是整个项目?

compiler-warnings swift xcode7

22
推荐指数
1
解决办法
5120
查看次数

有没有办法使用具有相同名称但返回类型不同的函数?

我的意图如下:

我的第一个功能:

public mutating func replaceSubstringInRange(_ range: CountableClosedRange<Int>, withString string: String) -> String
Run Code Online (Sandbox Code Playgroud)

我可以在print()例如上下文中使用它.

而我的第二个:

public mutating func replaceSubstringInRange(_ range: CountableClosedRange<Int>, withString string: String) -> Void
Run Code Online (Sandbox Code Playgroud)

只是为了修改某些东西

我知道需要不同的功能签名,但还有更好的方法吗?

methods declaration function swift

3
推荐指数
2
解决办法
662
查看次数

Swift的调用结果未使用

我无法弄清楚如何在swift3中删除此警告:

调用'responseMessagesArray'的结果未使用

这是我的代码的样子:

fileprivate class func getMessagesAtPath(_ path: String, tokenKey: String, completionHandler: @escaping (MyMessagesWrapper?, NSError?) -> Void) {
        let credentialData = ":\(tokenKey)".data(using: String.Encoding.utf8)!
        let base64Credentials = credentialData.base64EncodedString(options: [])

        let headers = ["Accept": "application/json",
                       "Content-Type": "application/json",
                       "Authorization": "Basic \(base64Credentials)"]

        Alamofire.request(path, headers: headers)
            .responseMessagesArray { response in
                if let error = response.result.error
                {
                    completionHandler(nil, error as NSError?)
                    return
                }
                completionHandler(response.result.value, nil)
        }
    }

    class func getMyMessages(_ completionHandler: @escaping (MyMessagesWrapper?, NSError?) -> Void) {
        getMessagesAtPath(MyMessages.endpointForMyMessages(),tokenKey: MyMessages.getTokenKey(),completionHandler: completionHandler)
    }

extension Alamofire.DataRequest {
    func responseMessagesArray(_ …
Run Code Online (Sandbox Code Playgroud)

xcode compiler-warnings ios swift swift3

1
推荐指数
1
解决办法
2916
查看次数