1

Followed the spotify swift tuturiol on youtube but currently getting the following error Argument labels '(contentsOfURL:, options:, error:)' do not match any available overloads for the following line:

if let imageData = NSData(contentsOfURL: imgURL, options: nil, error: &error) {

Context

func updateCoverArt() {
    if player?.currentTrackMetadata == nil {
        artworkImageView.image = UIImage()
        return
    }

    let uri = player?.currentTrackMetadata[SPTAudioStreamingMetadataTrackURI] as! String

    SPTAlbum.albumWithURI(NSURL(string: uri), session: session) { (error:NSError!, albumObj:AnyObject!) -> Void in
        let album = albumObj as! SPTAlbum

        if let imgURL = album.largestCover.imageURL as NSURL! {
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
                var error:NSError? = nil
                var coverImage = UIImage()

                if let imageData = NSData(contentsOfURL: imgURL, options: nil, error: &error) {
                    if error == nil {
                        coverImage = UIImage(data: imageData)!
                    }
                }

                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    self.artworkImageView.image = coverImage
                })

            })
        }
    }
}
cnichs27
  • 248
  • 3
  • 17
  • 2
    you no longer deal with `NSError` pointers in swift, but you have to use `do`, `try` and `catch` as error handling. The initializer looks like `public init(contentsOfURL url: NSURL, options readOptionsMask: NSDataReadingOptions) throws` – luk2302 Jan 20 '16 at 18:36
  • 1
    You can use `if let imageData = NSData(contentsOfURL: imgURL) { ... }` initialiser – Leo Dabus Jan 20 '16 at 18:40
  • @luk2302 any chance you could show what that looks like? thanks! – cnichs27 Jan 20 '16 at 19:02
  • you should actually do what Leo wrote since you do not pass any options. – luk2302 Jan 20 '16 at 19:03

0 Answers0