Echizzle
Echizzle

Reputation: 3459

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"];
        [self.camera startRecordingWithOutputUrl:outputURL];

Thank you for the help like always!

Upvotes: 0

Views: 52

Answers (1)

i_am_jorf
i_am_jorf

Reputation: 54640

This is what you want:

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

Upvotes: 2

Related Questions