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 = localPath
let inputFilePath = documentsDirPath.appendingFormat (folderPath)
var urlString = fileName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
urlString = "/".appending(urlString!)
let toURL = URL(string: documentsDirPath.appendingFormat (urlString!))
let fileURL = URL(string: inputFilePath.appendingFormat(urlString!))
print(toURL)
print(fileURL)
Comments
Post a Comment