Can't call function with argument list like '()'
I am new to IOS development. The AVAudioRecorder constructor AVAudioRecorder(URL: filePath, settings: nil, error: nil)
in the resource I am following, but I am coding in Swift 2 which has a different constructor.
Error Unable to call a function with a list of arguments of type "()" on the string " try audioRecorder = AVAudioRecorder(URL: filePath, settings: nil)
"
This is my sound file:
@IBAction func recordAudio(sender: UIButton) {
stopButton.hidden = false
recordButton.enabled = false
recordingInProgress.hidden = false
let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let currentDateTime = NSDate()
let formatter = NSDateFormatter()
formatter.dateFormat = "ddMMyyyy-HHmmss"
let recordingName = formatter.stringFromDate(currentDateTime)+".wav"
let pathArray = [dirPath, recordingName]
let filePath = NSURL.fileURLWithPathComponents(pathArray)
print(filePath)
var session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
} catch {}
do {
try audioRecorder = AVAudioRecorder(URL: filePath, settings: nil)
} catch {}
audioRecorder.meteringEnabled = true
audioRecorder.prepareToRecord()
audioRecorder.record()
}
+3
source to share
2 answers