SwiftUI macOS add costum file format (UTI)

152 Views Asked by At

I have a "normal" swiftUI macOS project, and I need to read some "custom" files like data.dat and data.DCA.
How do I add these extensions to my Xcode project?
At the moment I use the following code to read the data, but for non standard file extensions I just get the error:

Error Domain=NSCocoaErrorDomain Code=260 "The file “test.dat” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/UserName/*/RandomAppName/test.dat, NSUnderlyingError=0x600001af0450 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}


       
        
        let userName = NSUserName()
        let path = "/Users/\(userName)/*/RandomAppName/test.dat" 
        var savedData = Data()
        var savedString = String()
        do {
            let url = URL(fileURLWithPath: path)
   
        savedData = try Data(contentsOf: url)
 
        if let ssavedString = String(data: savedData, encoding: .utf8) {
            savedString = ssavedString
           print(savedString)
           
        }
        } catch {
        print(error)
        }

0

There are 0 best solutions below