Moussdog
Moussdog

Reputation: 67

Error " Value of type 'String' has no member 'URLbyAppending' " with my Record Function

I'm getting an error with my record audio function ... it says " Value of type 'String' has no member 'URLbyAppending' "

    func startRecording() {
        let audioFilename = getDocumentsDirectory().URLbyAppending("recording.m4a")
        let audioURL = NSURL(fileURLWithPath: audioFilename)

        let settings = [
            AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
            AVSampleRateKey: 12000.0,
            AVNumberOfChannelsKey: 1 as NSNumber,
            AVEncoderAudioQualityKey: AVAudioQuality.High.rawValue
        ]

It's very annoying because before with my Xcode 6 it was working perfectly...

I need some help please... Thank you

EDIT

Here is my getDocumentsDirectory Function

    func getDocumentsDirectory() -> String {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentsDirectory = paths[0]
    return documentsDirectory

Upvotes: 0

Views: 2104

Answers (1)

David Berry
David Berry

Reputation: 41226

Your getDocumentsDirectory function, which you should have included, apparently returns a string, not a URL. Fix it by using stringByAppendingPathComponent.

Alternatively, you can change your getDocumentsDirectory function to return a url directly and changing your calling to:

func getDocumentsDirectory() throws -> NSURL {
    return try NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
}

let audioUrl = try getDocumentsDirectory().URLByAppendingPathComponent("recording.m4a")

Note that since getDocumentsDirectory can throw (URLForDirectory can throw) getDocumentsDirectory must be called with try.

Upvotes: 2

Related Questions