Swfit 2“额外参数”错误“在通话中”

编程入门 行业动态 更新时间:2024-10-24 01:55:10
本文介绍了Swfit 2“额外参数”错误“在通话中”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在理解xcode想要什么,当它给我调用中的额外参数'错误'时它一直有问题它一直指向

I've been having a problem understanding what xcode wants from me when it gives me the "Extra argument 'error' in call" it keeps pointing to

if let feed = NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers, error: nil) as? NSDictionary,

我在swift 2中读到的地方我应该添加 do {但每次我添加它我只是不断打破更多的东西。 swift 2中的正确语法是什么?

I read somewhere that in swift 2 I should add do { but everytime I add it I just keep breaking more stuff. What's the correct syntax in swift 2?

这是代码:

override func viewDidLoad() { super.viewDidLoad() let request = NSURLRequest(URL: NSURL(string: feedURL)!) NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { response, data, error in if let feed = NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers, error: nil) as? NSDictionary, title = feed.valueForKeyPath("feed.entry.im:name.label") as? String, artist = feed.valueForKeyPath("feed.entry.im:artist.label") as? String, imageURLs = feed.valueForKeyPath("feed.entry.im:image") as? [NSDictionary] { if let imageURL = imageURLs.last, imageURLString = imageURL.valueForKeyPath("label") as? String { self.loadImageFromURL(NSURL(string:imageURLString)!) } self.titleLabel.text = title self.titleLabel.hidden = false self.artistLabel.text = artist self.artistLabel.hidden = false } } }

推荐答案

以下是swift 2中新的错误处理方式...

Here is the new way of error handling in swift 2...

do { if let feed = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) as? NSDictionary { // Success block... } } catch { print(error) }

更多推荐

Swfit 2“额外参数”错误“在通话中”

本文发布于:2023-11-26 07:06:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633121.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   参数   Swfit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!