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
@avii-7
avii-7 / PropertyWrapper.md
Last active September 4, 2024 17:50
SwiftUI

Property Wrapper

Property Wrappers in Swift allows you to extract common logic in a distinct wrapper object.

When dealing with properties that represent some form of state, it is very common to have some kind of associated logic that gets triggered every time a value is modified. For example, we might validate each new value according to a set of rules, we might transform our assigned value in some way.

For example, let's say that we want to create a property wrapper that automatically capitalizes all String values that were assigned to it. That might be implemeneted like this.

@avii-7
avii-7 / Chapter1.md
Last active February 12, 2025 16:55
Dispatch Mechanisms In Swift

Static vs Dynamic Dispatch in Swift

It's important to know the difference between static and dynamic dispatch for optimizing the code and better performance.

What is Dispatch ?

In this context, dispatching just refers to the action of finding the right function to call.

Static Dispatch

@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(())
@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 / 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 / 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