concept didisguise in category ios

appears as: DIDisguise, DIDisguise
Hello! iOS Development

This is an excerpt from Manning's book Hello! iOS Development.

Figure 7.6. The DIDisguise and DIDisguiseElement classes
Figure 8.11. New properties and messages in DIDisguise and DIDisguiseElement

OK, that’s nice, but this only works if DIDisguise can overlay disguises. Add this message to Disguise, and don’t forget to declare it in Disguise’s header:

-(UIImage*) overlayDisguisesOnFace:(UIImage *)face
{
    UIImage *newFace = face;
    for (DIDisguiseElement *d in self.elements) {
        newFace = [d overlayOnFace:newFace];
    }
    return newFace;
}

See what you’re doing? You’re making each model class responsible for its part. DIDisguise is responsible for telling elements that they’re supposed to overlay, but elements do the heavy lifting. Here’s what’s happening.