History
Loading...
Loading...
October 4, 2025
#Preview with multiple configurations by creating extension functions. Add func previews() -> some View to your views and call different states like .previews() in your preview block. This gives you instant visual feedback for all your view states without rebuilding.Multiple preview configurations allow you to visualize different states, themes, and accessibility conditions simultaneously in Xcode's canvas, catching UI issues early in development.
struct UserProfileView: View {
let user: User
let isLoading: Bool
var body: some View {
VStack {
AsyncImage(url: user.avatarURL)
Text(user.name)
if isLoading {
ProgressView()
}
}
}
}
#Preview("Default") {
UserProfileView(
user: User.sample,
isLoading: false
)
}
#Preview("Loading State") {
UserProfileView(
user: User.sample,
isLoading: true
)
}
#Preview("Dark Mode") {
UserProfileView(
user: User.sample,
isLoading: false
)
.preferredColorScheme(.dark)
}
#Preview("Accessibility") {
UserProfileView(
user: User.sample,
isLoading: false
)
.environment(\.dynamicTypeSize, .accessibility3)
}This approach prevents shipping UI bugs by making edge cases visible during development. You can spot layout breaks, color contrast issues, and accessibility problems without running the app on different devices or changing system settings repeatedly.