Reputation: 1
I am working on a decibel measuring app for my class, and I have been stumped by an error that keeps on coming up: 'ambiguous use of appendingPathComponent'. Here is where the problem is occurring:
//set up the URL for the audio file
var documents: AnyObject = NSSearchPathForDirectoriesInDomains( FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0] as AnyObject
var str = documents.appendingPathComponent("recordTest.caf")
var url = NSURL.fileURL(withPath: str as String)
The error is happening here:
var str = documents.appendingPathComponent("recordTest.caf")
I can't seem to get this resolved.
Help, Paul
Upvotes: 0
Views: 166
Reputation: 318824
Why are you casting documents
to AnyObject
? Get rid of that.
But that then brings up a new issue since appendingPathComponent
is a method of NSString
, NSURL
, or URL
. But documents
is a String
.
And why use NSURL
instead of URL
?
Since your goal is to get a URL
, use the more direct approach with FileManager
:
let docURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let url = docURL.appendingPathComponent("recordTest.caf")
Upvotes: 1