|
Hello, I'm having problems getting data back from documents directory to show it in my List. Saving function seems to be working fine:
However, when i try to loadData, it shows me an error: dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end around line 1, column 3." UserInfo={NSDebugDescription=Garbage at end around line 1, column 3., NSJSONSerializationErrorIndex=3}))) This is the loadData function.
What could be the problem? Does my saving function doesn't save data properly? Here is my Person structure:
|
|
It looks like you are not encoding the data before saving. Your save fuction is saving over the same file "url" 3 times. |
|
I think the problem is with your
It looks like you are writing the name and id to the file in UTF8 format, and then converting the image to But also, it looks like your I would recommend using something like this instead...
Since you have already written |
|
@Fly0strich Thank you, the problem with saving function was that i didn't encode it, you're right. But that was not the only thing - i had a lot of unnecessary stuff there which caused to save stuff as dictionary, not array of all people. I commented out the unnecessary stuff and now everything is working fine! :) Here is the final code that is giving me the expected outcome.
|
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.