Group Group Group Group Group Group Group Group Group

Trying to record audio file is not being saved


My code is trying to record sound and display it on a tableview. However it appears that the audio is not being saved. I am seeing this message in my log file.

    2019-01-13 11:11:07.926903-0500 recrod sound[2902:31076] 317: ca_debug_string: inPropertyData == NULL

I do not know what that means. It appears that no audio is being recorder and when i click on it in the tableview it is not working. I am trying to follow this tutorial

           import UIKit;import AVFoundation

    class ViewController: UIViewController, AVAudioRecorderDelegate, UITableViewDataSource, UITableViewDelegate {
var recordingSessioin: AVAudioSession!
var audioRecorder: AVAudioRecorder!
var aduioPlayer : AVAudioPlayer!

@IBOutlet var mytableVie3w : UITableView!

var numberOfRecords = 0
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 {
    aduioPlayer = try AVAudioPlayer(contentsOf: path)

    catch {

@IBOutlet var buttonL:UIButton!

@IBAction func record() {

    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
            buttonL.setTitle("Stop", for: .normal)
        catch {
            displayALert(title: "Ups", message: "Recording Failed")


    else {
        audioRecorder = nil
        buttonL.setTitle("Start", for: .normal)

        UserDefaults.standard.set(numberOfRecords, forKey: "myN")


override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.

    recordingSessioin = AVAudioSession.sharedInstance()

    AVAudioSession.sharedInstance().requestRecordPermission { (hasPermsionn) in
        if hasPermsionn{

    if let number:Int = UserDefaults.standard.object(forKey: "myN") as? Int
        numberOfRecords = number

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: "dismiss", preferredStyle:     .alert)
    alert.addAction(UIAlertAction(title: "diss", style: .default, handler: nil))

    present(alert, animated: true, completion: nil)
1 Like

You should try to follow the tutorial all the way and you will learn from it. He tells you how to refresh the data in the table view.


I am not having a problem with the table view refreshing I am having trouble because I can not save the audio clips.


But what I mean is, if you don’t refresh the table, how do you know it does (or doesn’t) record?


Were you ever able to solve this issue?


Had the same problem… Thanks


hi @samjonas,
if you can articulate the problem in detail, someone can help find a solution.

You must contact the author of that you tube video and ask them for details on how to solve your problem.