Will it cause a address lost when run in other devices?

I used cocoapods to install a third-party library called CSV.swift to read .csv files in my app. And I used a local path to let the library read the file. When I add the .csv file to my project I check Copy items if needed. Does it make sure my app won’t crash because file address lost when run in other devices? If not, how can I fix the problem?

If your .csv file is included in your project, then you should read it from the Bundle, not from a local path. That absolute path won’t be available on other devices.

1 Like

Could you explain it further? :pray: :pray: :pray: I know how to create a bundle and add files into it, but I don’t know how to read file from it making the file available when running on the other devices.
Thanks for your reply

This may help

It’s reading images, but same thing

https://www.hackingwithswift.com/read/1/2/listing-images-with-filemanager

1 Like

You would do something like this:

if let csvFile = Bundle.main.path(forResource: "language" ofType: "csv") {
    let stream = InputStream(fileAtPath: csvFile)
    //do whatever else you gotta do
} else {
    //gracefully handle your error
}
1 Like

I have solved the problem with all of your help. Thank you so much :pray: :pray: :pray: .