我需要url filepath是一个NSURL。我有这个:
let paths = NSSearchPathForDirectoriesInDomains( .DocumentDirectory,.UserDomainMask,true) // NSString *documentsDirectory = [paths objectAtIndex:0]; let documentsDirectory = paths[0] as String var filePath:String? = nil var fileNamePostfix = 0 do { filePath = "\(documentsDirectory)/\(dateTimePrefix)-\(fileNamePostfix++).mp4" } while (NSFileManager.defaultManager().fileExistsAtPath(filePath))
我需要将其转换为NSURL以在self.fileOutput.startRecordingToOutputFileURL(< #outputFileURL:NSURL?#>,recordingDelegate:< #AVCaptureFileOutputRecordingDelegate?#>)方法中使用。
我试过filePath? NSURL()但是不正确
谢谢!
你需要做:
let fileUrl = NSURL(string: filePath)
要么
let fileUrl = NSURL(fileURLWithPath: filePath)
取决于您的需要。见NSURL docs