Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
Swift - Import and open custom file extensions

I have to open a custom file within the app I am building but I am not sure how to do this. The file imported just contains folders within it which contains a plist

for example fileName.customExtension/name uuid/name.plist

if I open the custom file copy and paste the other folder "name uuid" into a regular folder which then I import in the app it works fine.

for example fileName/name uuid/name.plist

So how could i import the folder with the custom extension directly in the app?

I wrote the code below if the custom file is dropped in to the app to test at the moment but it doesn't work as I am guessing I am not converting the extension into a regular folder but instead just removing it.

func loadImportedFiles(){

    var fileName: String = ""
    let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    do {
        let fileUrls = try FileManager.default.contentsOfDirectory(at: documentsDirectoryURL, includingPropertiesForKeys: nil)
        for plist in fileUrls {
            let path: String = plist.path
            let file = URL(fileURLWithPath: path).lastPathComponent

            if file.contains(".CustomExtension"){
                fileName = URL(fileURLWithPath: path).deletingPathExtension().lastPathComponent
            }
        }
    } catch {
        print("error path")
    }

    var objCBool: ObjCBool = true
    let mainPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
    let folderPath = mainPath + "/Folder/\(fileName)"

    let isExist = FileManager.default.fileExists(atPath: folderPath, isDirectory: &objCBool)
    if !isExist {
        do {
            try FileManager.default.createDirectory(atPath: folderPath, withIntermediateDirectories: true, attributes: nil)
        } catch {
            print(error)
        }
    }


    let originalDataFilePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("\(fileName).CustomExtension")
    let newDestinationPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("Folder/\(fileName)")

    do { try FileManager.default.moveItem(at: originalDataFilePath!, to: newDestinationPath!)
        print("imported")
    } catch {
        print(error)
    }


}

If someone could guide me in the right direction that would be great thanks!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The solution is to use Custom File Types in the Info Plist. You will need to add "Exported Type UTIs" and "Document types" to the Info Plist. Then your custom files will be recognised.

Below is the tutorial I used to implement it.

https://chariotsolutions.com/blog/post/importing-data-via-custom-file-types-in/

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!