Skip to content

Instantly share code, notes, and snippets.

View kirti-swiggy's full-sized avatar
:dependabot:
tch tch

Kirti Verma kirti-swiggy

:dependabot:
tch tch
View GitHub Profile
@kirti-swiggy
kirti-swiggy / OfferCarouselView.swift
Last active February 5, 2023 15:31
A horizontal carousel view in SwiftUI with automatic and manual scroll support. Created using TabView.
//
// OfferCarousalView.swift
// Playground
//
// Created by Kirti Kumar Verma on 04/01/23.
//
import Combine
import Kingfisher
import SwiftUI
@kirti-swiggy
kirti-swiggy / VisibilityModifier.swift
Created February 6, 2023 10:33
ViewModifier to track when the View is visible if it's embedded in ScrollView.
struct VisibilityModifier: ViewModifier{
let positionOffset : Double
let height = UIScreen.main.bounds.height
func body(content: Content) -> some View {
GeometryReader { geometry in
let position = geometry.frame(in: CoordinateSpace.global).midY
ZStack {
Color.clear
if height >= (position + positionOffset) {
@kirti-swiggy
kirti-swiggy / Xcode14BuildStuckFix.md
Last active February 7, 2025 13:51
Fix for Xcode 14 getting stuck while rebuilding on macOS Ventura (13)

The Problem

The latest addition to Xcode's long list of bugs is the problem of Simulator screen going black and getting stuck. We need to manually kill the simulator and rebuild the project. This gets really frustrating if your project has significant build time.

The Workaround

You may follow following steps as a workaround till Apple fixes the issue in upcoming Xcode releases.

// The SwiftUI Lab
// Website: https://swiftui-lab.com
// Article: https://swiftui-lab.com/alignment-guides
import SwiftUI
class Model: ObservableObject {
@Published var minimumContainer = true
@Published var extendedTouchBar = false
@Published var twoPhases = true
@kirti-swiggy
kirti-swiggy / coolSearchPlaceholder.swift
Last active April 2, 2023 12:17
Search bar to display multiple categories in placeholder. See demo - https://imgur.com/a/9A2byvc
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
// MARK: Private properties
private var sections: [String] = ["restaurants", "groceries", "handpicked items", "convenience"]
@State private var currentIndex = 0
@State private var offsetY: CGFloat = 20
@kirti-swiggy
kirti-swiggy / sample.swift
Created October 19, 2023 04:33 — forked from chriseidhof/viewmirror.swift
View Inspection
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
}
}
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {
@kirti-swiggy
kirti-swiggy / new-swiftui-view.codesnippet
Created December 5, 2023 14:12
Code snippet for new SwiftUI view
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>new</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>TopLevel</string>
</array>
@kirti-swiggy
kirti-swiggy / AdaptsToSoftwareKeyboard.swift
Created December 24, 2023 15:53 — forked from scottmatthewman/AdaptsToSoftwareKeyboard.swift
An example of using Combine to automatically adapt a SwiftUI scrollable view to accommodate an iOS onscreen keyboard
import SwiftUI
import Combine
struct AdaptsToSoftwareKeyboard: ViewModifier {
@State var currentHeight: CGFloat = 0
func body(content: Content) -> some View {
content
.padding(.bottom, currentHeight)
.edgesIgnoringSafeArea(.bottom)
@kirti-swiggy
kirti-swiggy / View+Discover.swift
Created February 13, 2024 08:00 — forked from IanKeen/View+Discover.swift
SwiftUI: discover underlying components to fill in gaps in SwiftUI api
import SwiftUI
extension View {
public func discover<T: UIView>(
tag: Int = .random(in: (.min)...(.max)),
where predicate: @escaping (T) -> Bool = { _ in true },
_ closure: @escaping (T) -> Void
) -> some View {
self.overlay(
DiscoveryView(tag: tag)
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var number: Int = 1
@State var dummyFlag: Bool = true
@State var isIncrement: Bool = false // forgive me for this, this is just for demonstration. Surely there are better ways
var body: some View {
Rectangle()