Echizzle Echizzle - 1 year ago 57
Swift Question

Translating code from Objective-C to Swift issues

In my app I want to add the following Objective-C code in Swift,

- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];

My attempt has quite a few issues, aside from the syntax not being correct it seems that NSDocumentDirectory and NSUserDomainMask don't exist in Swift.

var applicationDocumentsDirectory : NSURL {

return NSFileManager.defaultManager().URLsForDirectory(NSDocumentDirectory, inDomains: NSUserDomainMask.lastObject)

The reason I'm using this computed property is that I need to pass an output URL to this camera framework I'm using as such...

// start recording
NSURL *outputURL = [[[self applicationDocumentsDirectory]
URLByAppendingPathComponent:@"test1"] URLByAppendingPathExtension:@"mov"];
[ startRecordingWithOutputUrl:outputURL];

Thank you for the help like always!


This is what you want:

NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).last