Url string return nil iOS swift issue
Solution:
If your filename had space then it returns nil while convert it into URL.So use the addingPercentEncoding to replace the space to %20 then it will works good.
If your filename had space then it returns nil while convert it into URL.So use the addingPercentEncoding to replace the space to %20 then it will works good.
let fileManager = FileManager.default
let folderPath = loc alPath
let inputFilePath = documentsDirPath.appendingForm at(folderPath)
var urlString = fileName.addingPercentEncoding (withAllowedCharacters: .urlQueryAllowed)
urlString = "/".appending(urlString!)
let toURL = URL(string: documentsDirPath.appendingForm at(urlString!))
let fileURL = URL(string: inputFilePath.appendingFormat( urlString!))
print(toURL)
print(fileURL)
Comments
Post a Comment