skip to content

Images and Symbols

Image covers asset catalogs and SF Symbols with rendering modes and effects, while AsyncImage loads remote images. Interviewers ask about scaling, caching and placeholders.

on this pageshow

explore

questions

6

In SwiftUI, how does an SF Symbol from Image(systemName:) differ from an asset-catalog Image(_:) in how it sizes and takes colour?

level: juniorimportance: must knowfreq 70%

answer

  1. glyph versus picture
  2. the font sizes a symbol
  3. imageScale is relative, not absolute
  4. natural point size until resizable()
  5. template images take foregroundStyle

basics

~20 s

An SF Symbol behaves like a text glyph: font(:) and imageScale(:) size it and foregroundStyle colours it. A bitmap asset draws at its natural point size in its own colours until you make it resizable() or template-rendered.

solid answer

~50 s

`Image(systemName:)` loads a vector symbol that SwiftUI sets like a character of text: it takes its point size and weight from the environment's `font`, `imageScale(.small)`, `.medium` or `.large` adjusts it relative to that font, and it draws as a template, so `foregroundStyle` colours it. `Image("chef-hat")` loads a picture from the asset catalog at its natural point size, choosing the @2x or @3x variant for the screen; a font does not resize it, so you add `resizable()` and an aspect ratio to scale it. It keeps its authored colours unless the asset's Render As setting or `renderingMode(.template)` makes it a template. A custom symbol stored as a symbol image set is the exception: it behaves like an SF Symbol. Both initialisers take a string, so a typo appears only at runtime; since iOS 17, Xcode's generated `ImageResource` constants such as `Image(.chefHat)` catch asset typos at compile time.

code

swift · 27 lines
swift
import SwiftUI

struct RecipeHeader: View {
    let title: String
    let minutes: Int

    var body: some View {
        HStack(spacing: 12) {
            Image("chef-hat")
                .resizable()
                .scaledToFit()
                .frame(width: 44, height: 44)
            VStack(alignment: .leading) {
                Text(title)
                    .font(.headline)
                Label("\(minutes) min", systemImage: "clock")
                    .font(.subheadline)
                    .foregroundStyle(.secondary)
            }
            Spacer()
            Image(systemName: "star.fill")
                .font(.title3)
                .imageScale(.large)
                .foregroundStyle(.yellow)
        }
    }
}

go deeper

for a junior

Recall the contrast: symbols size with font and imageScale and colour with foregroundStyle; asset bitmaps keep their natural size and colours until resizable() or template rendering.

for a middle

Explain template versus original rendering, why imageScale is relative to the font, and how the @2x and @3x variants set an asset's point size.

for a senior

Show production habits: ImageResource constants to catch renamed assets, custom symbol image sets for brand icons that follow Dynamic Type, and template icons that adapt to dark mode.

for a principal

Frame the icon policy a team adopts: system symbols first, custom symbols for brand marks, bitmaps only for photos, so icons scale, tint and stay consistent across the app.

## Two kinds of picture behind one type SwiftUI's `Image` is a single view type, but the picture behind it can be one of two very different things. An **SF Symbol**, created with `Image(systemName: "star.fill")`, is a vector glyph from Apple's symbol set, designed to sit beside text in nine weights and three scales. An **asset image**, created with `Image("chef-hat")`, is a picture you added to the app's asset catalog: usually a PNG, JPEG or HEIC bitmap supplied at @2x and @3x, sometimes a PDF or SVG vector. Apple's documentation describes `Image` as a late-binding token: the system resolves the actual picture only when it is about to draw it in an environment, which is why the environment (font, colour, scale) can change how the same `Image` value looks. ## How an SF Symbol takes its size A symbol is sized the way text is sized, not the way a photo is. - **`font(_:)`** sets its point size and weight. `Image(systemName: "clock").font(.subheadline)` matches a subheadline `Text` beside it, and because text styles follow Dynamic Type, the symbol grows with the user's text size. - **`imageScale(_:)`** takes `Image.Scale.small`, `.medium` or `.large` and scales the symbol *relative to the current font*. Apple's documentation calls it a scale "to apply to vector images relative to text"; it is not a point size. - **`fontWeight(_:)`** or a weighted font changes the stroke weight, so a symbol can match bold text. - **`resizable()`** works on a symbol too, but it then scales the glyph as a picture to whatever frame it gets, losing its tie to the neighbouring text's size. Inside a `Label` or interpolated into a `Text`, a symbol also lines up with the words around it, which is why toolbar and list icons are almost always symbols. ## How an asset image takes its size A bitmap asset has a fixed natural size in points: a 300 × 300-pixel @3x image lays out as 100 × 100 points. Until you call `resizable()` it keeps that size, and a font has no effect on it. To scale it you follow the usual chain: 1. `resizable()` lets the image take the size its frame offers. 2. `scaledToFit()` or `scaledToFill()` (both shorthands for `aspectRatio(contentMode:)`) keep the original proportions. 3. A `frame` decides the size, and `clipped()` hides any overflow from fill. The exception is a **custom symbol** exported from the SF Symbols app into a symbol image set in the catalog: `Image("custom.whisk")` then behaves like a system symbol, sized by the font and tinted by the foreground style. ## Colour: template versus original | | SF Symbol | Bitmap asset | |---|---|---| | Default rendering | template: the foreground style fills its shape | original: its own pixels | | Sized by | `font(_:)`, `imageScale(_:)` | its natural point size, or `resizable()` plus a frame | | Recoloured by | `foregroundStyle`, `symbolRenderingMode(_:)` | only after `renderingMode(.template)` or Render As Template | | Typo in the name | an empty image at runtime | an empty image at runtime, or a compile error with `ImageResource` | A **template** image uses only its shape (its alpha channel) and fills it with the current foreground style; an **original** image draws its own colours. So `.foregroundStyle(.orange)` turns a symbol orange but leaves a full-colour photo untouched. To tint a single-colour icon PNG, either set Render As to Template Image in the asset catalog or call `renderingMode(.template)` on the `Image`. ## Names, typos and type safety - `Image(systemName:)` and `Image(_:)` both take a `String`, so a misspelt name compiles and shows nothing when the screen runs. - Since iOS 17, `Image(_:)` also accepts an `ImageResource`. Xcode generates a static constant for each catalog image, turning `chef-hat` into `.chefHat`, so `Image(.chefHat)` fails to compile if the asset is renamed or removed. - System symbol names have no such generated constants; check them in the SF Symbols app, which also shows the iOS release each symbol needs. - `Image(decorative:)` and the `label:` initialisers decide what VoiceOver reads; that choice belongs with accessibility rather than rendering. ## What to say in an interview The crisp contrast is: **a symbol is text-like, an asset is picture-like**. Symbols take size and weight from the font and colour from the foreground style; assets keep their natural size and colours until you opt into resizing and template rendering. Naming the custom-symbol exception and `ImageResource` shows you have shipped real screens rather than memorised one example.

  • Why is font(_:) usually better than resizable() and a frame for sizing an SF Symbol?
    A font sets the symbol at a point size, so it tracks Dynamic Type through the text style, keeps its weight matched to the text and lines up with neighbouring words. `resizable()` scales the glyph as a picture to whatever frame it gets, so it no longer follows the text size and can distort if you forget an aspect ratio. Reserve `resizable()` for a large decorative symbol with a fixed frame.
  • What does Image(systemName:variableValue:) add for a symbol such as a signal-strength icon?
    Available since iOS 16, it passes a value from 0 to 1 that symbols with variable layers use to switch layers on progressively, such as the bars of `wifi` or `speaker.wave.3`. Only symbols designed with variable layers respond to it. It lets one symbol show a level without swapping symbol names.

  • An SF Symbol needs resizable() and a frame before it can change size.
  • imageScale(.large) sets an absolute point size for the symbol.
  • foregroundStyle recolours a full-colour asset photo the same way it tints a symbol.
  • A misspelt system symbol name is caught by the compiler.
  • A font modifier scales bitmap asset images along with the text.
open as a page

In SwiftUI, how do you show a placeholder, the loaded recipe photo and an error state with AsyncImage, and where do image modifiers go?

level: middleimportance: must knowfreq 64%

basics

~20 s

Use AsyncImage's phase initialiser: its closure receives AsyncImagePhase, and you return a placeholder for .empty, the image for .success and an error view for .failure. Image modifiers such as resizable() go on the Image inside the closure.

open as a page

In SwiftUI, how do you make recipe photos fill square grid thumbnails without stretching or spilling, and why is clipped() needed?

level: juniorimportance: should knowfreq 60%

basics

~10 s

Chain resizable() and scaledToFill() on the Image, give it a square frame, then clipped(). resizable() alone stretches each axis, fill keeps the aspect ratio but overflows the frame, and clipped() hides the overflow.

open as a page

In SwiftUI, how does renderingMode(_:) differ from symbolRenderingMode(_:), and when do you use monochrome, hierarchical, palette or multicolor?

level: middleimportance: should knowfreq 48%

basics

~10 s

renderingMode(:) works on any Image and chooses template (shape filled with the foreground style) or original (own pixels). symbolRenderingMode(:) works on SF Symbols' layers: monochrome, hierarchical, palette or multicolor.

open as a page

In a SwiftUI recipe grid, AsyncImage thumbnails show their placeholders again and re-download when scrolled back into view; what does AsyncImage cache, and how do you fix it?

level: seniorimportance: should knowfreq 44%

basics

~20 s

Before iOS 27, AsyncImage documents no cache and no download settings: it loads through the shared URLSession. From iOS 27 it caches image data following the transport protocol, init(request:) sets a cache policy and asyncImageURLSession(_:) supplies a session.

open as a page

In SwiftUI, how do symbolEffect(_:options:value:) and symbolEffect(_:options:isActive:) differ, and how do you animate a favourite heart filling in?

level: middleimportance: nice to knowfreq 32%

basics

~10 s

symbolEffect(:options:value:) plays a discrete effect such as bounce once each time an Equatable value changes; symbolEffect(:options:isActive:) runs an indefinite effect such as pulse while a Boolean is true. A heart filling in uses contentTransition(.symbolEffect(.replace)).

open as a page