i created a folder in my assets called "json" into there i dragged&dropped a file called code.json from the finder. Now i want to open the file but
Bundle.main.path(forResource: "code", ofType: "json", inDirectory: "json")
just returns nil.
I also tried to put it in the assets without the subfolder and using following way
Bundle.main.path(forResource: "code", ofType: "json")
with the same result.
Can anyone help me? What am i doing wrong?
You need to make the folder reference when you drag it to xcode , it's color is blue not yellow

//

It is clear from your question that you are trying to add the code.json file in Assets.xcassets and trying to access it's path with Bundle.main.path(forResource: ), which will always returns nil, because Assets.xcassets is present in Bundle and then your file exists in it.
Try adding the files directly to the project, as suggested in previous answer, approach is right, Bundle.main.path(forResource: "code", ofType: "json")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With