我的项目存在问题,它一直在:
之后请求预期的参数类型。 &安培;预期的分隔符我在上面请求插入它们的问题留下了评论。我很感激你的帮助。
// 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.
}
答案 0 :(得分:0)
您似乎正在尝试调用函数performGetRequest
,但您在开头使用func
来定义它。
如果这不是您的意图,也许您正在尝试定义该功能,但您必须小心完成处理程序。你可以看到正确的方法[{3}}。
最后,这是一个具有相同名称和类似问题的here函数。我不知道你的代码是否基于此代码,但可以澄清一下,看一下这个问题及其答案。
答案 1 :(得分:0)
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)") }
}
} }