Что не так с appendingPathComponent, это необязательно? - PullRequest
0 голосов
/ 06 марта 2020

Я не могу закрыть свой код, потому что это проблема, это еще не обязательно? В строке «if let rutaMemoria» появляется: «Инициализатор условного связывания должен иметь необязательный тип, а не« 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)
                }
            }
        }

, и когда я удаляю «if», xcode показывает мне эту ошибку в строка ниже (в recuerdos.append): «Переменная, используемая внутри собственного начального значения»

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)
            }
        }
    }

1 Ответ

0 голосов
/ 07 марта 2020

Нет, appendingPathComponent не является обязательным, it let только для дополнительных

Заменить

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

на

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