|
This is the first struct, it's a a custom swift file(Petition)
and this is the second one(Petitions)
and this is the whole code
I am having hard time understanding when the Petition file is actually used in the code? it seems the parse(json: Data) function is decoding into the Petitions file, rather than the Petition file. Also, the petitions property at the top of the class is being created as an instance of the Petitions file. So why is the Petition file there? and when is it used in the code? |
|
And it's also used here:
This takes the And it looks like you may not have gotten that far yet, but |
|
@roosterboy, thanks for clarifying. However, when we passed the variable data into the parse(json: Data) function, aren't we decoding our files inside Petition struct? if so, wouldn't that mean the Petition struct gets the files first, it then passes it onto the Petitions struct? If so, the Petition array is never used directly in the code, but the Petition struct is. I don't see how the Petitions struct is playing any role in this code. |
|
@Geeljira petitions the forum for clarification:
@rooster has the right answer. But to further clarify @twoStraw's intentions. A The You're correct. The parse JSON function is decoding into a Example:petitions = [ petition1, petition2, petition3, petition4 ] <- A collection of pets = [dog1, dog2, dog3, cat1, hampster1, cat2] <- A collection of Keep coding! |
|
Some math here, say we are doing some linear algebra and we have to find values of x, y and given 2 equations
Now we sove it, if we multiply eqiation one by 2 and equation 2 by 9 we get
Now we subtract
we get
now we substitute y in to equation one
we get
In short coding is like maths, we can do substitution and make changes as per our requirements , you and i will come across many situations where such substitutions are made , just understand its for our own understanding and if you can find another way to solve it , most welcome, just do not over think , every thing is maths based in coding , feel free to do as you wish do not feel constrained in your approach to solve, paul and other author make changes to make code easier to solve as per their way , you can have your way to solve as well |
|
Thought I might try a way. If You look at the json that Paul uses (Think it was taken from a web site)
So to get the array from You could also show as a nested
|
|
Thank you @Obelix and @NigelGee. I am currently working on the milestone that covers projects 13-15, and Paul recommends we use a mix of project1 and project7 to accomplish that. I get the big picture, but this little detail was throwing me off. I'll continue to read your responses again and again until I get it. I created you a json file and I will be loading it from disc. Idk how I'll show all three properties since there's only textLabel and detailTexlabel in the prototype cell, but I'll cross that bridge once I get there. here's my json file.
I appreciate you guys for your help. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.
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.