Skip to content

Instantly share code, notes, and snippets.

View atrinh0's full-sized avatar
🐾

An Huggins atrinh0

🐾
View GitHub Profile
@atrinh0
atrinh0 / scrollviewreader_crash.swift
Created August 29, 2022 14:41
ScrollViewReader scrollTo crash on Xcode 14
import SwiftUI
struct ContentView: View {
@State private var items: [RandomItem] = (0...25).indices.map { _ in RandomItem() }
var body: some View {
ScrollViewReader { proxy in
List {
ForEach(items) { item in
Text("\(item.number)")
@atrinh0
atrinh0 / menu_picker_selection_issue.swift
Created August 6, 2022 16:50
SwiftUI menu picker selection issue
import SwiftUI
struct ContentView: View {
@State private var selection: SortOrder = .ascending
var body: some View {
NavigationView {
VStack {
Text("Selected Sort Order:")
Text(selection.rawValue)
@atrinh0
atrinh0 / chart_opacity_glitch.swift
Created June 18, 2022 15:01
Swift Chart - Foreground style negative opacity glitch
import SwiftUI
import Charts
@available(iOS 16.0, *)
struct ContentView: View {
@State private var opacity = -0.5
var body: some View {
VStack {
Chart(SalesData.last30Days, id: \.day) {
@atrinh0
atrinh0 / chart_scroll_issue.swift
Last active September 19, 2022 14:36
Swift Charts - Scrolling performance
import SwiftUI
import Charts
@available(iOS 16.0, *)
struct ContentView: View {
@State private var selection: HashableItem?
var body: some View {
// MARK: - 1. Baseline performance test
// Scrolling is smooth, CPU averages around 10% when scrolling
@atrinh0
atrinh0 / heatmap_issue.swift
Last active August 13, 2022 14:16
Swift Charts - Heat Map compilation issue
import SwiftUI
import Charts
struct ContentView: View {
@State private var grid = Grid(numRows: 10, numCols: 10)
var body: some View {
if #available(iOS 16.0, *) {
VStack {
Spacer()
@atrinh0
atrinh0 / flag_quiz.swift
Created August 14, 2021 13:57
Flag Quiz Concept
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
HStack {
Image(systemName: "xmark")
.font(Font.title.weight(.bold))
.foregroundColor(.gray)
ZStack(alignment: .leading) {
@atrinh0
atrinh0 / picker_menu.swift
Created June 27, 2021 17:44
Picker Menu Style Label Issue
import SwiftUI
struct ContentView: View {
let options: [String] = ["ascending", "descending", "highest", "lowest"]
@State private var selectedOption = "ascending"
var body: some View {
NavigationView {
VStack {
Text("Image label")
@atrinh0
atrinh0 / pluraliser_issues.swift
Last active June 8, 2023 17:12
Foundation Pluraliser Potential Issues
import SwiftUI
struct ContentView: View {
// sample of data was compiled using the following sources:
// https://birdgei.com/2011/08/30/list-of-100-irregular-plural-nouns-in-english/
// https://www.grammarly.com/blog/plural-nouns/
// https://www.thoughtco.com/irregular-plural-nouns-in-english-1692634
// https://www.ef.co.uk/english-resources/english-grammar/singular-and-plural-nouns/
// google
@atrinh0
atrinh0 / pluraliser.swift
Last active June 10, 2021 09:40
Pluraliser
import SwiftUI
struct ContentView: View {
let animals = ["bear",
"buffalo",
"cow",
"fish",
"fox",
"goose",
"ox",
@atrinh0
atrinh0 / alignment_guides.swift
Last active June 10, 2021 09:40
SwiftUI Alignment Guides (aligning vertical to horizontal)
import SwiftUI
extension VerticalAlignment {
struct VertAlignName: AlignmentID {
static func defaultValue(in d: ViewDimensions) -> CGFloat {
d[.top]
}
}
static let vertAlignName = VerticalAlignment(VertAlignName.self)
}