Demystifying Views in iOS · File's Owner | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4518-demystifying-views-in-ios/lessons/4

Hi @catie,

I felt a little slower than usual for this chapter. I’m not sure if these are dumb questions or not:

  • I’m not entirely clear on where all this stuff lives in a project so consequently I’m not clear on why I can’t reference what’s going on in the Nib from the superview. eg. With my limited understanding, I know I can call methods in a class extension from another file, why can’t I reference the Nib from the superview that lives in a different file? What’s different about this structure? Is it a compiler thing?

  • When defining the flip method in CardView, why did we know to define the side parameter as an Optional Side? Wouldn’t all CardViews have sides?

  • Why are we defining handleFlip as a closure instead of a method we can call elsewhere (is that related to the issue of not being about to nest classes in IB?) And why is it optional? (I’m starting to guess that in the future, we’re going to be defining other superview instances that have a different flip behaviour, and some that don’t handle flips at all?)

  1. What is it that you’d like to reference? (It may be helpful to keep in mind that this nib is going to be used in more than one place in the app. Having a stronger “connection” between it and any other class would likely make for less encapsulated code.)

  2. When a card gets “flipped”, without a side specified, it will just go to whatever side isn’t showing. But there will also be a need for the card to look like it’s flipping, even though the same side will be shown – just with different content. You could write this differently but we thought using the default parameter was the simplest way to express the concept: card.flip()

  3. A stored closure serves the same purpose as a delegate that only has one method. (Multiple stored closures are more flexible than a delegate with multiple methods, because what the closures store can come from various places, not just one object with methods of a prescribed name. So Catie and I tend to use closures in nearly all circumstances.) An optional is used because it’s reasonable for a card to flip but for nothing else to happen in response to that.

@jessycatterwaul Got it. This is all very helpful, much appreciated.

1 Like