DevPrep

All topics › UIKit

Difference between a view and a layer (CALayer)?

Junior PRO

The gist

UIView is a UIKit object: it takes part in the responder chain, Auto Layout and the controller hierarchy. CALayer is a Core Animation object: it stores bitmap content and geometry that the compositor renders on the GPU, and it can animate its properties. Every view owns a backing layer (view.layer) and is its delegate; the view's frame, bounds, center, alpha, backgroundColor are proxies to the layer (layer.frame, layer.bounds, layer.position, layer.opacity).

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store