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 / 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(())
@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 / 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 / COW.md
Last active September 4, 2024 07:59
Swift Learnings

Swift — “copy-on-write”

"copy on write" is an optimization technique that helps in managing memory more efficiently.

It is used primarly with value types such as Array, Dictionary and String to defer the actual copying of data until it is modified. This helps in minimizing unnecessary data copying and thus improve performance.

How "copy on write" works ?

When you assign or pass a value type to another variable or function. Swift doesn't immediately creates the copy of data. Instead it shares the same underlying storage until the copy is modified.

@avii-7
avii-7 / A10.swift
Last active September 4, 2024 19:20
Array - DSA Questions
// Print all Divisors of a given Number | A10.swift
var arr = [Int]()
// x = sqr(n)
// TimeComlexity = O(x + xlog(x) + x)
for i in 1...n where i * i <= n {
if n % i == 0 {
arr.append(i)
@avii-7
avii-7 / 1. DispatchQueueBasic.md
Last active August 9, 2024 16:04
Multi-Threading - Swift

DispatchQueue Basics

Introduction

DispatchQueue is an object that manages the execution of tasks serially or concurrently on main thread or on a background thread.

Serial Custom DispatchQueue

A custom DispatchQueue ensures that tasks are executed one at a time in the order they are added.

Brochette-case / Kebab case => Hello_World
lowerCamelCase / Dromedary Case => helloWorld
Pascal case / Upper Camal Case => HelloWorld
Snake case
Snake case starts with a lower case letter, and uses an underscore to separate words (although some variations start with an upper case).
Generally associated with the C programming language, although it actually started life with no particular name:
first + _ + Number = first_Number
Examples: my_func(), my_var, name, test