I get no errors or anything, but when I run the app it crashes. The log I get is "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MPConcreteMediaItem imageWithSize:]: unrecognized selector sent to instance 0x14eefa3b0'".
I think the line that causes this problem is this one:
cell?.imageView?.image = sortedResults[indexPath.row].imageWithSize(imageSize)
because when I delete it/uncomment it, everything works fine.
imageSizeis a CGSize var.
The whole Code:
let startTime: NSTimeInterval = NSDate().timeIntervalSince1970
let songsQuery: MPMediaQuery = MPMediaQuery.songsQuery()
let songsArray: [MPMediaItem] = songsQuery.items!
let songsNSArray : NSArray = NSArray(array: songsArray)
let descriptor: NSSortDescriptor = NSSortDescriptor(key: MPMediaItemPropertyLastPlayedDate, ascending: false)
let sortedResults: NSArray = songsNSArray.sortedArrayUsingDescriptors([descriptor])
let finishTime: NSTimeInterval = NSDate().timeIntervalSince1970
NSLog("Execution took %f seconds to return %i results.", finishTime - startTime, sortedResults.count)
cell?.textLabel?.text = sortedResults[indexPath.row].title
cell?.detailTextLabel?.text = sortedResults[indexPath.row].artist
cell?.imageView?.image = sortedResults[indexPath.row].imageWithSize(imageSize)
sortedResults[indexPath.row]does not have a methodimageWithSize(imageSize: CGSize)implemented. - TimMPMediaItemobjects. Why do you think one of those has animageWithSizefunction? - Phillip MillsNSArrayin Swift. - Sulthan