Is it safe to force unwrap `FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!` in Swift?

Viewed 32

I'm not sure if urls(for: .documentDirectory, in: .userDomainMask) could be an empty array or not, so I'm not sure if it is a good idea to make the following FileManager extension, can someone give me some advice? Thanks.

import Foundation

extension FileManager {
    var documentDirectory: URL {
        // Is it safe to force unwrap in this specific case❓
        urls(for: .documentDirectory, in: .userDomainMask).first!
    }
}

// use case
FileManager.default.documentDirectory
0 Answers
Related