Skip to content

Instantly share code, notes, and snippets.

View avii-7's full-sized avatar
🚣
On a raft.

A V I I avii-7

🚣
On a raft.
View GitHub Profile
1. EXC_BAD_ACCESS (code=2) always means `Stack Overflow`
2. bt in Xcode lldb for backtrace.
@avii-7
avii-7 / AsyncStream.swift
Last active February 5, 2026 17:04
Deallocation Issue
import SwiftUI
final class StreamListner {
private let stream: AsyncStream<Int> = AsyncStream<Int> { (continuation) in
Task {
for i in 1...20 {
try? await Task.sleep(for: .seconds(2))
continuation.yield(i)
}
@avii-7
avii-7 / Notes.txt
Created February 4, 2026 07:18
SwiftUI Update Mechanism
Changes in construction parameters cause the view's body to re-evaluate regardless of that
parameter is using in the body or not.
SwiftUI cannot determine whether this change will cause value of body to change or not, it will blindly re-evalute the body.
@avii-7
avii-7 / LegendView.swift
Created January 23, 2026 06:44
LegendView just like HTML Legend and FieldSet
//
// LegentView.swift
// DifferentSmallTests
//
// Created by Arun's Macbook on 22/01/26.
//
// Support only one line for Legend Text right now.
import SwiftUI
@avii-7
avii-7 / SafeAreaEdges.swift
Created December 21, 2025 16:37
Safe Area Edges for SpriteKit
//
// SKScene+Edges.swift
// SafeAreaEdges
//
// Created by Arun on 21/12/25.
//
import SpriteKit
// Make sure to access through `viewDidLayoutSubviews` method of ViewController.
@avii-7
avii-7 / SliderOverlay.swift
Last active October 10, 2025 17:39
Anchor Preference & Overlay Preference
/*
Displaying a bubble that follows the slider thumb using the `anchorPreference` and
`overlayPreferenceValue` modifiers in SwiftUI.
*/
import SwiftUI
struct OverlayPreferenceKey: PreferenceKey {
typealias Value = Anchor<CGRect>?
@avii-7
avii-7 / BlurredButtonView.swift
Created June 25, 2025 17:03
UIButton with BlurEffect
// Don't use this if you care about number of lines for the label.
// Because in the latest syntax (UIButton.Configuration) there is no option for setting number of lines.
final class BlurredButtonView: UIButton {
private let gradientLayer = CAGradientLayer()
let titleFont: UIFont
let verticalSpacing: CGFloat
let horizontalSpacing: CGFloat
@avii-7
avii-7 / PageStyleTabViewIssue.swift
Created April 28, 2025 04:54
Page Style TabView is not respecting ignoreSafeArea inside NavigationStack
/*
There is a bug in SwiftUI, some how ignoreSafeArea(.top) don't work when you add PageStyle TabView inside NavigationStack.
This bug is reproduceable in minimum iOS 16.6
Solution: Just add color to TabView.
*/
struct ContentView: View {
var body: some View {
myTabView
@avii-7
avii-7 / Shimmer.swift
Created December 12, 2024 18:10
Shimmer Animation
import Foundation
import SwiftUI
extension View {
@ViewBuilder
func shimmer(when isLoading: Bool) -> some View {
if isLoading {
self.modifier(Shimmer())
.redacted(reason: .placeholder)
@avii-7
avii-7 / Series.swift
Created September 23, 2024 17:45
Print Series
func execute() {
let numberChannel = AsyncChannel<Void>()
let alphabetsChannel = AsyncChannel<Void>()
Task {
var iterator = (1...10).makeIterator()
for await _ in numberChannel {
if let number = iterator.next() {
print(number, terminator: " ")
await alphabetsChannel.send(())