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()
}
}
}