Saving Data in iOS 路 Codable Types | Ray Wenderlich


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6307-saving-data-in-ios/lessons/12

Hi @jessycatterwaul, thanks for the great course. I have a question. Why didn鈥檛 the member-wise initialiser work for the Sticker struct? I tried initializing the member variables with var and it didn鈥檛 work as well.

At 5:08, I go over how it鈥檚 due to Swift not synthesizing a memberwise initializer for public access.

As for the var situation, I鈥檓 not sure what you鈥檙e asking. Please share a code snippet if you鈥檙e still working on this!

Hi, sorry for the confusion. I meant I tried changing the public let keyword to var to see if the member-wise initializer could work (which wouldn鈥檛 change anything :sweat_smile:). I get what you mean now. It is not publicly available. I was confused because I used to work on a project which I had a struct on one folder (group) and I could initialize it on a viewcontroller in another folder without having to write a boilerplate initializer. I鈥檓 still not sure why that one worked but I guess I might have missed something there. Thanks a lot anyway!

If you have files in separate folders in an Xcode project, the default option is for them to still be included in the same module, resulting in all the code in those files being able to communicate if you don鈥檛 modify the default access for that code, which is internal. There鈥檚 no way to elevate a memberwise initializer from internal to public, unfortunately, so you have to write it yourself if you want other modules to be able to use it. A playground page and its Sources folder are two different modules, for example. I鈥檓 not convinced that was a good design, but hopefully this clears things up a little bit.

He Jessy, this is sooo clear. Thanks a lot for taking time to answer me. I really appreciate it :vulcan_salute::grinning:

1 Like

Am I supposed to know everything in it by heart?? or Just understanding is good enough to move on??

Knowing any material by heart is going to make it faster to get things accomplished. But fortunately, software development is a lot more like composing a musical score rather than performing it. You can take all the time you need, and you鈥檒l just decrease your development time as you gain experience.

Knowing that you can understand what you鈥檙e learning is important, but it鈥檚 also important to be able to find the information that you鈥檝e learned, later, so you can study it again as you need to. Fortunately, search engines have made it so that we don鈥檛 need to take as copious of notes as we used to, in order to retrieve information in the world, but there鈥檚 still going to be a balance of mental cues, and a bookmarking system of some kind, that will be optimal for each individual. The trouble with telling you exactly how to do that is that it will be a unique mix.

In terms of the content on our site, feel free to explore in any order you like. We try to structure things so that they build on each other, but if you鈥檙e new to what we teach, you should expect that if you were to get through a lot of episodes, and then watch them again in order, that you鈥檇 understand all of the earlier ones better on later viewings. You鈥檒l learn a lot just by being immersed, seeing concepts used in many contexts, even if you don鈥檛 understand them as well as you want to. You can think of it like living in a foreign country without being a native speaker of the local language.

Good luck and have fun!

This is just all I would love to hear. I totally get that you mean. Thank you for your time.

1 Like

Hi Ray Wenderlich team. I鈥檓 really loving the iOS and Swift for Beginners path, I鈥檓 very grateful for all of the well organized content.

One piece of feedback, I鈥檝e noticed that it takes me a couple watch throughs of some videos before I really understand what it is that I鈥檓 doing and why I鈥檓 doing it. This video especially, it would be very beneficial to me if the video began with an overview of what we will be doing and why. To me, it鈥檚 initially clear that this lesson is about learning about the Codable protocol and how to encode JSON data, but then from there it feels like I鈥檓 just typing/executing code. Taking some time to layout a high level bullet point list of the main things we will be doing before diving into the bullet points themselves would add modular context that I could refer back to.

Currently, it feels like one long coding marathon that I get lost in. Throughout the video, you do pause to explain what it is that we just did every few minutes, but I鈥檓 still initially having trouble seeing how any one chunk fits into the bigger picture of what the lesson is actually about.

1 Like

@bachir0321 Thank you for your feedback - much appreciated! We will take it into account when we update the course.

Sorry my last post was a typo, but actually I cant compare the json due to:

**error: binary operator '==' cannot be applied to two 'Sticker' operands**

**jsonSticker == sticker**

could you share an update ?

Without seeing your code, the only reason I can think of is that you missed adopting Equatable (at the 1:35 mark in the video). If that鈥檚 not the case, upload your version of the project and I鈥檒l have a look!

Thank you, it Works like a Charm. I missed the Equatable

1 Like