StoreSearch (p.186): order of variables influences functionality?

I started adding the landscape mode to the StoreSearch app and came across something very peculiar. After adding the transitions and animations (before adding the scroll view) the DetailViewController suddenly didn’t show the correct data of the selected item anymore.

During debugging I learned, that the DetailViewController did not receive the searchResult despite the prepareForSegue function trying to update the searchResult variable in DetailViewController.

After some more debugging I noticed that the prepareForSegue function somehow did not try to update the searchResult variable, but the dismissAnimationStyle variable that I had put above the searchResult variable.

So when I moved the AnimationStyle enum as well as the dismissAnimationStyle variable below the searchResult variable, everything worked fine again. Rebooting the simulator and restarting Xcode hadn’t helped.

Does anyone have an idea why the order of the variables has an influence on the functionality in this case or in general? Any ideas or explanations are appreciated!

That sounds… odd. :wink:

The order of the variables does make a difference but not one you normally need to worry about. It determines the memory layout of the objects and this is the domain of the Swift compiler. Maybe the compiler did not realize you had made a change to DetailViewController and still assumed searchResult was in the place of the new dismissAnimationStyle variable. That’s the only way I can explain this.

If this happens again, try doing a clean: hold down the Alt/Option key, go to the Product menu and choose Clean Build Folder.

Glad to see that I’m not the only one finding that behavior odd. Your explanation sounds pretty reasonable.

That’s why I had tried even starting Xcode again, but I had forgotten to clean the build folder. Thanks for reminding me! :slight_smile: