Skip to content

Instantly share code, notes, and snippets.

View AXNameFromColorDemo.swift
import SwiftUI
struct AXNameFromColorDemo: View {
@State var color =
var body: some View {
VStack {
ColorPicker("Pick a color", selection: $color)
RoundedRectangle(cornerRadius: 25)
View ToolbarKeyboardViewBuilderProblem.swift
import SwiftUI
struct ContentView: View {
@FocusState var isFocused: Bool
@State var flag = true
@State var a = ""
@State var b = ""
var body: some View {
View TintInheritProblem.swift
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Group {
Button("Default") { }
// .tint(nil) works better than .accentColor(nil): it's app's accentColor
Button(".tint(nil)") { }
View TextElideProblem.swift
import SwiftUI
struct ContentView: View {
@State var value = -122.90
let range = -300.0...300
var body: some View {
VStack {
#warning("`alignment: .firstTextBaseline`, cause the Text inside Label is elided sometime")
HStack(alignment: .firstTextBaseline) {
View NavigationBarTitle.swift
import SwiftUI
struct Child: View {
var body: some View {
ScrollView(.vertical, showsIndicators: true) {
ForEach(1...100, id: \.self) {
Text("#\($0) Hello, world!")
View MatchedGeometryEffectTrouble.swift
import SwiftUI
// the matched geometry effect works in this version
struct MyGizmo: View {
@State private var setting = 1
@Namespace private var namespace
var body: some View {
HStack {
ForEach(1...3, id: \.self) { item in
View FocusDemoSimConsoleLog.txt
2021-08-24 16:58:32.244431-0700 SwiftUI30WWDC2021[58755:8413137] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
View TimeDisplay.swift
import SwiftUI
struct LocaleSpecificDateDisplay: View {
static let timeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm:ss.SSSz"
return formatter
static let timeZone = TimeZone(identifier: "Africa/Harare")!
View HierarchyList.swift
// Original article here:
import SwiftUI
struct FileItem: Identifiable {
var name: String
var children: [FileItem]?
View DisclosureGroupDisclosureBug.swift
import SwiftUI
struct ContentView: View {
@State private var show = false
var body: some View {
// DisclosureGroup doesn't work here, works in `List`
VStack {
#warning("doesn't show content on expand at all")
DisclosureGroup {