首页 > swift 重写方法无效

swift 重写方法无效

func post(url: String, params: [String: AnyObject], identifier: String? = nil) {
        Alamofire.request(.POST, url, parameters: params).responseData(completionHandler: { (response) in
            if let data = response.data {
                let json = JSON(data: data)
                self.netDelegate?.netSuccess!(json.description, identifier: identifier)
            } else {
//                self.netDelegate?.netError((.Net, "网络连接失败"), identifier: identifier)
            }
        })
    }
    func netSuccess(result: String, identifier: String?) {
        print("identifier:\(identifier)\nresult:\(result)")
    }
    
    func netError(err: AlamofireResultError, identifier: String?) {
        print("identifier:\(identifier)\nerr:\(err)")
    }

如上图代码;我在父类中封装了一个网络请求,并且实现了协议里面的两个方法(netSuccess,netError);我希望能在子类中使用更方便,但是,目前的结果却是,子类调用post方法,且重写了两个协议方法(netSuccess,netError)后,子类的(netSuccess,netError)方法一直没法调用,一直只调用父类的两个方法,请问这是什么问题?


不能再扩展里面写。只能在类里面重写


self.netDelegate这个你是怎么初始化的?

【热门文章】
【热门文章】