Ho un file PDF nel mio DocumentDirectory
.Rinomina file in DocumentDirectory
Desidero che l'utente sia in grado di rinominare questo file PDF in qualcos'altro se lo desidera.
Avrò un UIButton
per iniziare questo processo. Il nuovo nome verrà da UITextField
.
Come posso fare? Sono nuovo di Swift e ho trovato solo informazioni su Objective-C e sto avendo difficoltà a convertirlo.
Un esempio del percorso del file è:
/var/mobile/Containers/Data/Application/39E030E3-6DA1-45FF-BF93-6068B3BDCE89/Documents/Restaurant.pdf
ho questo codice per vedere verificare se il file esiste o no:
var name = selectedItem.adjustedName
// Search path for file name specified and assign to variable
let getPDFPath = paths.stringByAppendingPathComponent("\(name).pdf")
let checkValidation = NSFileManager.defaultManager()
// If it exists, delete it, otherwise print error to log
if (checkValidation.fileExistsAtPath(getPDFPath)) {
print("FILE AVAILABLE: \(name).pdf")
} else {
print("FILE NOT AVAILABLE: \(name).pdf")
}
Non lo sapevo. L'ho modificato un po 'e ha funzionato alla grande. Grazie! – ChallengerGuy
Prego. – Moritz
per favore aggiungi un esempio Swift 3. Thx –