Reputation: 1699
My Error is: Value of type 'String' has no member 'URLByAppendingPathComponent'
I got error in this line :
let savePath = documentDirectory.URLByAppendingPathComponent("mergeVideo-\(date).mov")
My full code:
// 4 - Get path
let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .LongStyle
dateFormatter.timeStyle = .ShortStyle
let date = dateFormatter.stringFromDate(NSDate())
let savePath = documentDirectory.URLByAppendingPathComponent("mergeVideo-\(date).mov")
let url = NSURL(fileURLWithPath: savePath)
I followed this tutorial : Here
Upvotes: 4
Views: 11368
Reputation: 285082
It's
let savePath = (documentDirectory as NSString).stringByAppendingPathComponent("mergeVideo-\(date).mov")
since documentDirectory
is a String
rather than an NSURL
Edit
I recommend to use this API:
let documentDirectory = try! NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .LongStyle
dateFormatter.timeStyle = .ShortStyle
let date = dateFormatter.stringFromDate(NSDate())
let saveURL = documentDirectory.URLByAppendingPathComponent("mergeVideo-\(date).mov") // now it's NSURL
Swift 3+
let documentDirectory = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
var dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .short
let date = dateFormatter.string(from: Date())
let saveURL = documentDirectory.appendingPathComponent("mergeVideo-\(date).mov")
Upvotes: 8
Reputation: 81
Swift 3: URL appendingPathComponent
let documentDirectory = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let completeMovie = documentDirectory.appendingPathComponent("movie.mov") // now it's NSURL
Swift 3 Path
let fm = FileManager.default
let docsurl = try! fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let completeMovie = String(describing: docsurl.appendingPathComponent("merge.mp4"))
Upvotes: 0
Reputation: 107141
As the error states, there is no URLByAppendingPathComponent
method available for String
class, that function belongs to NSURL.
You need to use:
let savePath = (documentDirectory as NSString).stringByAppendingPathComponent("mergeVideo-\(date).mov")
Or you can do it like:
let url = NSURL(fileURLWithPath: documentDirectory)
let savePath = url.URLByAppendingPathComponent("mergeVideo-\(date).mov")
Upvotes: 1