IPhone Dev - Where to Put Lazy Download Code

I already had such a question, but I deleted it anyway.

I have a very simple application with a root view controller, and it switches between two other views manager views. Therefore, in my root view controller, it lazily loads instances of two other view controllers. Each time the switch button on the toolbar is pressed, the current displayed controller (its presentation) is unloaded (set to zero), and a new one is loaded and added to the preview.

Since I load controllers of my kind and unload them at certain times, the lazy load code that is in the getters is very confusing because I actually don't want to load them correctly when I use them, I need to load them before the flip animation will look good. Therefore, I think I want to load the loadFirstVC and loadSecondVC methods for loading view controllers. Is that a good idea?

+4
source share
1 answer

The main reason for lazy loading is NOT to delay the download that will definitely happen. This puts off a download that will never be needed. (This is also useful for forcing a reboot when changing data, but that is not your problem here.)

Example. Let's say you have a bunch of data about a person, including a photo that is stored in an external file. But the photo will be displayed only if the user goes into the preview, so why download the photo from its file until you know exactly what the preview will be displayed? Boom, use lazy loading.

By the time you KNOW you want to download a certain piece of data, it is hardly very important when you download it.

When does it matter? Well, this is really a matter of optimization. They say that you may have encountered; if you haven’t done this, it’s just as good as everyone: “Premature optimization is the root of all (programming) evil.”

So ask yourself two questions:

  • Is a piece of data needed? If NO, proceed with the lazy loading method. If YES, go to question 2.

  • Is this when loading data? [An example would be, it is huge, and I don’t want to download it until I UNLOAD something else to make room for it] If NO, put it in any place that works. If YES ... Go back and ask us again and provide more details.

... I suspect that this does not answer your original question, but it looks like you might be asking the wrong question first. Sorry if I'm wrong.

+6
source

All Articles