我的 swift 项目上的编码错误缺少预期/参数&&分隔符



我的项目有一个问题,它一直在请求:之后的预期参数类型&预期的分隔符我在上面留下了一个问题的评论,我被要求插入它们。我很感激你的帮助。

        // expected parameter type following ':' &             expectedseperator ,
        func performGetRequest(targetURL: NSURLRequest, completion: { (data, HTTPStatusCode, error) -> Void in
            if HTTPStatusCode == 200 && error == nil {
            // Convert the JSON data to a dictionary.
            let resultsDict = NSJSONSerialization.JSONObjectWithData(data!, options: nil, error: nil) as! Dictionary<NSObject, AnyObject>
            let items: AnyObject! = resultsDict["items"] as AnyObject!
            let firstItemDict = (items as! Array<AnyObject>)[0] as! Dictionary<NSObject, AnyObject>
            let snippetDict = firstItemDict["snippet"] as! Dictionary<NSObject, AnyObject>
            var desiredValuesDict: Dictionary<NSObject, AnyObject> = Dictionary<NSObject, AnyObject>()
            desiredValuesDict["title"] = snippetDict["title"]
            desiredValuesDict["description"] = snippetDict["description"]
            desiredValuesDict["thumbnail"] = ((snippetDict["thumbnails"] as! Dictionary<NSObject, AnyObject>)["default"] as! Dictionary<NSObject, AnyObject>)["url"]

            desiredValuesDict["playlistID"] = ((firstItemDict["contentDetails"] as! Dictionary<NSObject, AnyObject>)["relatedPlaylists"] as! Dictionary<NSObject, AnyObject>)["uploads"]
            self.channelsDataArray.append(desiredValuesDict)
            self.tblVideos.reloadData()
            ++self.channelIndex
            if self.channelIndex < self.desiredChannelsArray.count {
            self.getChannelDetails(useChannelIDParam)
            }
            else {
            self.viewWait.hidden = true
            }
            } else {
            println("HTTP Status Code = (HTTPStatusCode)")
            println("Error while loading channel details: (error)") }
            })
    }        
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

您似乎试图调用函数performGetRequest,但一开始是用func定义的。

如果这不是你的意图,也许你正在尝试定义函数,但你必须小心使用完成处理程序。你可以在这里看到正确的方法。

最后,这里有一个关于一个同名函数和类似问题的问题。我不知道你的代码是否基于此,但看看这个问题及其答案可能会有所澄清。

var desiredChannelsArray = ["eminemvevo", "Google", "disney"]
    var channelIndex = 0
    var channelsDataArray: Array<Dictionary<NSObject, AnyObject>>.Type?

    override func viewDidLoad() {
        super.viewDidLoad()
    }  class helper {
        func performGetRequest(targetURL: NSURL!, completion: (data: NSData?, HTTPStatusCode: Int, error: NSError?) -> Void) {
            let request = NSMutableURLRequest(URL: targetURL)
            request.HTTPMethod = "GET"
            let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
            let session = NSURLSession(configuration: sessionConfiguration)
            let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    completion(data: data, HTTPStatusCode: (response as! NSHTTPURLResponse).statusCode, error: error)})})

            task.resume()
        }
    }
    func getChannelDetails(useChannelIDParam: Bool) {
        var urlString: String!
        if !useChannelIDParam {
            urlString = "https://www.googleapis.com/youtube/v3/channels?part=contentDetails,snippet&forUsername=(desiredChannelsArray[channelIndex])&key=(apiKey)"
        } else {
        }
        let targetURL = NSURL(string: urlString)
        func performGetRequest(targetURL: NSURL!, completion: (data: NSData?, HTTPStatusCode: Int, error: NSError?) -> Void) {
            if HTTPStatusCode == 200 && error == nil{
                // Convert the JSON data to a dictionary.
                let resultsDict = NSJSONSerialization.JSONObjectWithData(data!, options: nil, error: nil) as! Dictionary<NSObject, AnyObject>}
            let items: AnyObject! = resultsDict["items"] as AnyObject!
            let firstItemDict = (items as! Array<AnyObject>)[0] as! Dictionary<NSObject, AnyObject>
            let snippetDict = firstItemDict["snippet"] as! Dictionary<NSObject, AnyObject>
            var desiredValuesDict: Dictionary<NSObject, AnyObject> = Dictionary<NSObject, AnyObject>()
            desiredValuesDict["title"] = snippetDict["title"]
            desiredValuesDict["description"] = snippetDict["description"]
            desiredValuesDict["thumbnail"] = ((snippetDict["thumbnails"] as! Dictionary<NSObject, AnyObject>)["default"] as! Dictionary<NSObject, AnyObject>)["url"]

            desiredValuesDict["playlistID"] = ((firstItemDict["contentDetails"] as! Dictionary<NSObject, AnyObject>)["relatedPlaylists"] as! Dictionary<NSObject, AnyObject>)["uploads"]
            self.channelsDataArray.append(desiredValuesDict)
            self.tblVideos.reloadData()
            ++self.channelIndex
            if self.channelIndex < self.desiredChannelsArray.count {
                self.getChannelDetails(useChannelIDParam)
            }
            else {
                self.viewWait.hidden = true
            }
        } else {
            print("HTTP Status Code = (HTTPStatusCode)")
            print("Error while loading channel details: (error)") }
    }
}
}

相关内容

  • 没有找到相关文章