Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

289
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda