I am baffled as to what I should be using in Swift 3 for the following code:
func fileExist(_ filePath:AnyObject) -> Bool {
let PdfPathWithFileName = filePath.appendingPathComponent(fileName as String)
let fileManager = FileManager.default
return fileManager.fileExists(atPath: PdfPathWithFileName)
}
I have tried changing the AnyObject
to String
but then I get another error:
'appendingPathComponent' is unavailable: Use appendingPathComponent on URL instead
Any ideas?
String
now exposes a method appendingPathComponent(_:)
. You no longer have to cast your String
to an NSString
. The answer below is no longer correct (And may have been out-of-date when I posted it.)
The method appendingPathComponent
is a method of NSString. You need to make your parameter an NSString
if you want to pass in a string. Otherwise pass in an NSURL