For me atleast, “FileManager.fileExists” is finding my .json file in the App-directory but but NOT the .jpg files. I have solved by problem by not using it for the .jpg files.But there appears to be a problem with “FileManager.fileExists”. The problem is made clearer in my Feb 6, 2020 11:29 AM post.I don’t recommend that anybody use my Swift coding as an example to follow.
Post
Replies
Boosts
Views
Activity
There is a fileExists problem (at least for me)!Had to work around this fileExists problem by ignoring the supposed non-existence of the .jpg files, and by changing myloadDirImage to return nil when it can’t load the files.Relavent code:func fileExists(url: URL) -> Bool { do { let fileManager = FileManager.default try fileManager.fileExists(atPath: String(contentsOf: url)) } catch { return false } return true} fileprivate func _guaranteeImage(name: String) -> _ImageDictionary.Index { if let index = images.index(forKey: name) { return index } let url = trailFileURL.appendingPathComponent("\(name).jpg") //fileExists is unable to fine .jpg files in the App Directory!!! TODO if fileExists(url: trailDataURL) {print("\(trailDataURL) exists")} else {print("\(trailDataURL) NOexists")} if fileExists(url: url) {print("\(url) exists")} else {print("\(url) NOexists")} let image = ImageStore.loadDirImage(url: url) if image != nil { images[name] = image } else { images[name] = ImageStore.loadImage(name: name) ImageStore.copyImage(name: name) } return images.index(forKey: name)! }fileExists Can’t find the .jpgs:file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/margarette-falls.jpg NOexistsloadDir file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/margarette-falls.jpgfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/silversalmoncreek.jpg NOexistsloadDir file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/silversalmoncreek.jpgfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/chilkoottrail.jpg NOexistsloadDir file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5CD9C0D0-12E5-426B-8C9A-D31B9D40AB8C/Documents/chilkoottrail.jpgBut the .jpgs were there, and then deleted:Name-iMac:Documents name$ ls -ltotal 848-rw-r--r-- 1 name staff 63243 Feb 5 15:14 chilkoottrail.jpg-rw-r--r-- 1 name staff 52721 Feb 5 15:13 margarette-falls.jpg-rw-r--r-- 1 name staff 309101 Feb 5 15:13 silversalmoncreek.jpg-rw-r--r-- 1 name staff 1249 Feb 6 07:41 trailData.jsonName-iMac:Documents name$ rm *.jpgName-iMac:Documents name$ ls -ltotal 8-rw-r--r-- 1 name staff 1249 Feb 6 07:41 trailData.jsonName-iMac:Documents name$ No .jpgs in Documents, so the app loads from the Bundle and then copys then to Documents.file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/margarette-falls.jpg NOexistsload file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Bundle/Application/7DF72A83-2F9E-4692-BF68-C715960CD2AF/LocalTrails.app/margarette-falls.jpgcopy file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Bundle/Application/7DF72A83-2F9E-4692-BF68-C715960CD2AF/LocalTrails.app/margarette-falls.jpg -> file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/margarette-falls.jpgfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/silversalmoncreek.jpg NOexistsload file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Bundle/Application/7DF72A83-2F9E-4692-BF68-C715960CD2AF/LocalTrails.app/silversalmoncreek.jpgcopy file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Bundle/Application/7DF72A83-2F9E-4692-BF68-C715960CD2AF/LocalTrails.app/silversalmoncreek.jpg -> file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/silversalmoncreek.jpgfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/chilkoottrail.jpg NOexistsload file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Bundle/Application/7DF72A83-2F9E-4692-BF68-C715960CD2AF/LocalTrails.app/chilkoottrail.jpgcopy file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Bundle/Application/7DF72A83-2F9E-4692-BF68-C715960CD2AF/LocalTrails.app/chilkoottrail.jpg -> file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/DE02E870-B97D-477A-9EBE-6F65F81EC691/Documents/chilkoottrail.jpgName-iMac:Documents name$ ls -ltotal 848-rw-r--r-- 1 name staff 63243 Feb 5 15:14 chilkoottrail.jpg-rw-r--r-- 1 name staff 52721 Feb 5 15:13 margarette-falls.jpg-rw-r--r-- 1 name staff 309101 Feb 5 15:13 silversalmoncreek.jpg-rw-r--r-- 1 name staff 1249 Feb 6 07:41 trailData.jsonName-iMac:Documents name$ fileExists Can’t find the .jpgs that the App copied to Documents:file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/margarette-falls.jpg NOexistsloadDir file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/margarette-falls.jpgfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/silversalmoncreek.jpg NOexistsloadDir file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/silversalmoncreek.jpgfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/trailData.json existsfile:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/chilkoottrail.jpg NOexistsloadDir file:///Users/name/Library/Developer/CoreSimulator/Devices/3AD300AB-EA56-4877-AD85-C117E5CE240F/data/Containers/Data/Application/5606123A-7240-4692-9B67-CCE8BAE09CCC/Documents/chilkoottrail.jpg
Additional info:The .jpg files were copied in terminal from the project-resources to the App-directory, but the .json file was put there by the App.