jeudi 5 mars 2020

What's wrong with appendingPathComponent, is it optional?

I can't close my code because an issue, is it optional yet? In the 'if let rutaMemoria' line it appears: "Initializer for conditional binding must have Optional type, not 'URL'"

    for archivo in archivos {

        let nombreArchivo = archivo.lastPathComponent

            if nombreArchivo.hasSuffix(".thumb") {
                let sinExtension = nombreArchivo.replacingOccurrences(of: ".thumb", with: "")

                if let rutaMemoria = obtenerDirectorioDocs().appendingPathComponent(sinExtension){
                recuerdos.append(rutaMemoria)
                }
            }
        }

and when I remove the 'if', xcode shows me this error in the line below (in recuerdos.append): "Variable used within its own initial value"

for archivo in archivos {

    let nombreArchivo = archivo.lastPathComponent

        if nombreArchivo.hasSuffix(".thumb") {
            let sinExtension = nombreArchivo.replacingOccurrences(of: ".thumb", with: "")

            let rutaMemoria = obtenerDirectorioDocs().appendingPathComponent(sinExtension){
            recuerdos.append(rutaMemoria)
            }
        }
    }

Aucun commentaire:

Enregistrer un commentaire