patternswiftMinor
Show a quiz from JSON in iOS
Viewed 0 times
showiosquizjsonfrom
Problem
I have to create a quiz of showing questions from a JSON and post back the answers.
Here's the structure of JSON:
My Attempt
I have created a
Here's the structure of JSON:
{
"pp": [
{
"profile_property": {
"circle_value": 4,
"created_at": null,
"id": 1,
"name": "THIS IS THE QUESTION TO DISPLAY",
"updated_at": null,
"profile_property_values": [
{
"circle_value": 1,
"created_at": null,
"description": null,
"id": 1,
"profile_property_id": 1,
"standard": true,
"updated_at": "2014-01-24T13:34:47+05:30",
"value": "OPTION 1",
"image": "imageURL",
"sel_image": "selectedImageURL"
},
{
"circle_value": 2,
"created_at": null,
"description": null,
"id": 2,
"profile_property_id": 1,
"standard": true,
"updated_at": "2014-01-24T13:34:47+05:30",
"value": "OPTION @",
"image": "imageURL",
"sel_image": "selectedImageURL"
},
{
"circle_value": 3,
"created_at": null,
"description": null,
"id": 3,
"profile_property_id": 1,
"standard": true,
"updated_at": "2014-01-24T13:34:47+05:30",
"value": "OPTION #",
"image": "imageURL",
"sel_image": "selectedImageURL"
}
]
}
},
{
"profile_property": {},
{
"profile_property": {},
{
"profile_property": {}
],
"style_profile": {
}
}
}My Attempt
I have created a
loaderVCSolution
It appears that your
The
Every time we set the
When there's an error loading the data, we just stop showing a spinner. Sure, we do a
But if all we're doing in this
Finally, if somehow, our network request completes before the view is finished appearing, we'll actually run into problems. You can't segue away from a view before it is finished appearing yet, and your code implements no logic to verify that
Answer struct is basically being used as a global singleton. It's hard to tell, because not everything is included here, but you've included your loaderVC, and the logic in that is hard to follow.The
loaderVC appears to exist purely for the sake of taking care of some of the loading logic. I'm not entirely certain how much I like that, but the problem is that there's a complete disconnect from loading the data and doing anything with the results. Every time we set the
styleQuizData property, we immediately segue. No matter what we set it to, even nil.When there's an error loading the data, we just stop showing a spinner. Sure, we do a
println, but the end user can't see that and we don't log that in a meaningful way that is useful once the app hits the app store. And from a user experience point of view, this is horrendous. These are the sort of apps that I just uninstall. When it breaks and doesn't tell me, but just sits there, I am not happy at all as an end user, so we need a better way of handling load errors (which won't be uncommon... you're doing networking...).But if all we're doing in this
loaderVC is simply loading the quiz data, it seems a pretty strong case for moving the loading logic to the previous view controller or to the next view controller. Yes, you will likely want some sort of temporary view to indicate that loading is happening, but not an entire view controller (which we get stuck on if the load fails).Finally, if somehow, our network request completes before the view is finished appearing, we'll actually run into problems. You can't segue away from a view before it is finished appearing yet, and your code implements no logic to verify that
loaderVC is ready to move forward before it presents another view controller. This is even more reason that our loading should be initialized from either our previous or next view controller rather than a view controller in the middle simply for the sake of loading the data.Context
StackExchange Code Review Q#92782, answer score: 2
Revisions (0)
No revisions yet.