Delete TableView: Value of type has no member

on Line 117, I'm getting the error "Value of type 'Int' has no member 'remove'

Any ideas?

My code was working great as a simple record and play back app, and when I'm trying to add the ability to delete rows, I'm getting an error on line 117.

Ideas anyone?



import UIKit
import AVFoundation
class FirstViewController: UIViewController, AVAudioRecorderDelegate, UITableViewDelegate, UITableViewDataSource {

    var recordingSession:AVAudioSession!
    var audioRecorder:AVAudioRecorder!
    var audioPlayer:AVAudioPlayer!
   
    var numberOfRecords:Int = 0
   
    @IBOutlet weak var buttonLable: UIButton!
    @IBAction func record(_ sender: Any)
    {
        /
        if audioRecorder == nil
        {
            numberOfRecords += 1
            let filename = getDirectory().appendingPathComponent("\(numberOfRecords).m4a")
            let settings = [AVFormatIDKey: Int(kAudioFormatMPEG4AAC), AVSampleRateKey: 12000, AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue]
           
            /
            do
            {
                audioRecorder = try AVAudioRecorder(url: filename, settings: settings)
                audioRecorder.delegate = self
                audioRecorder.record()
               
                buttonLable.setTitle("Stop Recording", for: .normal)
            }
            catch
            {
                displayAlert(title: "oops!", message: "recording failed loser")
            }
        }
        else
        {
            /
            audioRecorder.stop()
            audioRecorder = nil
            UserDefaults.standard.set(numberOfRecords, forKey: "myNumber")
            myTableView.reloadData()
           
            buttonLable.setTitle("Start Recording", for: .normal)
        }
    }
    @IBOutlet weak var myTableView: UITableView!
   
    override func viewDidLoad() {
        super.viewDidLoad()
        /
        /
        recordingSession = AVAudioSession.sharedInstance()
       
        if let number:Int = UserDefaults.standard.object(forKey: "myNumber") as? Int
        {
            numberOfRecords = number
        }
       
        AVAudioSession.sharedInstance().requestRecordPermission { (hasPermission) in
            if hasPermission{
                print ("ACCEPTED")
            }
        }
    }
    @IBAction func bookAmazon(_ sender: UIButton) {
        if let url = URL(string: "http:/
            UIApplication.shared.open(url, options: [:])
    }
}
    /
    func getDirectory() -> URL
    {
        let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
        let documentDirectory = paths[0]
        return documentDirectory
       
    }
    /
    func displayAlert(title:String, message:String)
{
    let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "dismiss", style: .default, handler: nil))
    present(alert,animated: true, completion: nil)
   
    }
   
   
   
    /
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return numberOfRecords
    }
   
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = String(indexPath.row + 1)
        return cell
    }
   
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
    {
        let path = getDirectory().appendingPathComponent("\(indexPath.row + 1).m4a")
       
        do
        {
            audioPlayer = try AVAudioPlayer(contentsOf: path)
            audioPlayer.play()
        }
        catch
        {
           
            /
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
            {
                if editingStyle == UITableViewCellEditingStyle.delete
                {
                    numberOfRecords.remove(at: indexPath.row)
                    tableView.reloadData()
                   
                }
            }
           
           
        }

"numberOfRecords" is just the number of rows in your table, representing (apparently) the number of files already recorded. For your deletion code to work, it needs to be an array of the names of the recorded files.


That means several other changes to your code. You would need to maintain the array properly, and use the name from the array instead of constructing the file names in (e.g.) lines 96 and 102.

Thank you Quincey,


This makes sense, and I appreciate you reply. I had a feeling it was somehow related to an array. in fact, those were the two lines I've been playing with. But, when I changed the ( ) to [ ] it broke the code. I had a feeling it was not going to be that simple for me. I'm a beginner, and sometimes, end up overwhemled. But, I'm sticking at it!


It feels good, however to know I was looking at the right lines of code!


I'm just a bit lost on what I might change to fix it up.

Or, is there a different approach to deleting rows that could work with the code how I set it up?

Here's what I would recommend (based on the code fragment you posted, which may not account for other complexities):


— Discard your "numberOfRecords" instance property, and replace it with (say) "recordedFileNames: [String]" — that is, an array of strings.


— Anywhere where you needed to know the number of recorded files, use recordedFileNames.count.


— When you record a new file, assign it a new number (but don't re-use a number that's already in use!), and add the corresponding name to your array.


— Whenever you need to populate a table cell label with the name, use indexPath.row to index into the array, rather than constructing the name each time.


— When you need to delete a recording, remove the corresponding element from the array, and delete the corresponding file.

Hey it seems we're trying to create a similar app fromt the same tutorial. Did you ever solve the issue here? I'm struggling with the same problem and I'm extremely new to xcode so I have no clue where to go from here.


Thanks,
-M

Delete TableView: Value of type has no member
 
 
Q