History
Loading...
Loading...
September 22, 2025
.redacted(reason: .placeholder) with onAppear to create native shimmer loading effects. The system automatically generates appropriate placeholder content that matches your actual view structure without additional dependencies.This approach uses SwiftUI's built-in redacted modifier to create loading states that automatically match your actual content structure. The placeholder content provides the proper sizing and layout while the shimmer effect gives users clear feedback that content is loading.
struct ContentView: View {
@State private var isLoading = true
@State private var userData: UserData?
var body: some View {
VStack(alignment: .leading, spacing: 16) {
HStack {
Circle()
.frame(width: 60, height: 60)
VStack(alignment: .leading) {
Text(userData?.name ?? "Sample User Name")
.font(.headline)
Text(userData?.email ?? "sample@email.com")
.font(.subheadline)
.foregroundColor(.secondary)
}
}
Text(userData?.bio ?? "This is a sample bio text that shows what the actual content will look like when loaded")
.font(.body)
}
.padding()
.redacted(reason: isLoading ? .placeholder : [])
.task {
await loadUserData()
}
}
private func loadUserData() async {
try? await Task.sleep(nanoseconds: 2_000_000_000)
userData = UserData(name: "John Doe", email: "john@example.com", bio: "iOS Developer")
isLoading = false
}
}Native redacted modifiers ensure consistency with system design patterns, reduce bundle size by avoiding third-party shimmer libraries, and automatically adapt to different content types and accessibility settings. The placeholder content maintains proper layout dimensions, preventing jarring layout shifts when real data loads.