I'm struggling to find a way to pass parameter using the #selector. I've gone over some similar questions however keep getting similar errors. Can someone explain how to do this properly please? I need to get the urlString to print however I get the following error:
Argument of '#selector' does not refer to an '@objc' method, property, or initializer
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! SearchiTunesResultCell
let song = songs[indexPath.item]
cell.song = song
cell.songTitle.text = "Song: \(song.trackName ?? "")"
cell.artistName.text = "Artist: \(song.artistName ?? "")"
cell.albumName.text = "Album: \(song.collectionName ?? "")"
cell.playPauseButton.addTarget(self, action: #selector(handlePlayPreview(url: song.previewUrl!)), for: .touchUpInside)
return cell
}
@objc func handlePlayPreview(url: String) {
print("playing URL:", url)
}