DevPrep

All topics › Auto Layout

Content hugging vs compression resistance?

Middle PRO

The gist

These are two priorities that Auto Layout attaches to the intrinsic content size along each axis:

Both are optional constraints (< 1000), so when space runs out the system "breaks" the one with the lower priority. Hugging matters when there is more space than needed; compression resistance when there is less.

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