Search code examples
iosswift3xcode8

'pathExtension' is unavailable: Use pathExtension on URL instead


This code gives an error 'pathExtension' is unavailable: Use pathExtension on URL instead:

if originalAudioFormat == "MP2" || originalAudioFormat == "BWFMP2" {
                    SourceFileNameWithPath = decodeMp2ToWav() 

                        if SourceFileNameWithPath.pathExtension != "wav" { //error at this line
                            print("save File as PCM Fehler: \(SourceFileNameWithPath)")
                            return
                            }

Solution

  • Basically it's highly recommended to prefer always URLs to String paths.

    Alternatively you can bridge the string to NSString

    (SourceFileNameWithPath as NSString).pathExtension
    

    Please conform to the naming convention that variable names start with a lowercase letter.