Skip to content

Instantly share code, notes, and snippets.

View gopalkrishnareddy's full-sized avatar

Gopal Krishna Reddy Thotli gopalkrishnareddy

  • Harman India
  • Bangalore
View GitHub Profile
@yspreen
yspreen / ContentView.swift
Last active June 2, 2025 11:10
Sticky Section Header
/**
* ContentView.swift
* StickyTest
*
* Created by Nick Spreen (spreen.co) on 5/28/25.
*
*/
import SwiftUI
@stephancasas
stephancasas / NSApplication+openSettings.swift
Last active May 30, 2025 22:51
An extension enabling global access to settings scene of a macOS SwiftUI application.
//
// NSApplication+openSettings.swift
//
// Created by Stephan Casas on 12/3/23.
//
import SwiftUI;
fileprivate let kAppMenuInternalIdentifier = "app"
fileprivate let kSettingsLocalizedStringKey = "Settings\\U2026";
extension StringProtocol {
subscript(_ offset: Int) -> String.Element {
if offset >= 0 {
self[index(startIndex, offsetBy: offset)]
} else {
self[index(endIndex, offsetBy: offset)]
}
}
@lukepistrol
lukepistrol / TaskTrigger.swift
Last active November 19, 2023 19:32
Attach async tasks to SwiftUI views using a trigger mechanism.
import SwiftUI
struct TaskTrigger<T: Equatable>: Equatable {
fileprivate enum TaskState<S: Equatable>: Equatable {
case inactive
case active(value: S, uniqueId: UUID? = nil)
}
fileprivate var state: TaskState<T> = .inactive
//
// TranslucentTitleBarApp.swift
// TranslucentTitleBar
//
// Created by Alexander Sandberg on 20.10.22.
//
import SwiftUI
@main
@lukepistrol
lukepistrol / AsyncButton.swift
Created October 17, 2022 21:00
A SwiftUI Button that can perform asyncronous tasks.
import SwiftUI
/// A control that initiates an action asyncronously.
///
/// You create a button by providing an action and a label.
/// The action is either a method or closure property that
/// does something when a user clicks or taps the button.
/// The label is a view that describes the button’s action —
/// for example, by showing text, an icon, or both:
///
public extension Spacer {
static func maxHeight(_ value: CGFloat) -> some View {
Spacer(minLength: 0)
.frame(maxHeight: value)
.layoutPriority(-1)
}
static func maxWidth(_ value: CGFloat) -> some View {
Spacer(minLength: 0)
@Amzd
Amzd / DictionaryKeyPath.swift
Last active June 15, 2025 13:20 — forked from casperzandbergenyaacomm/DictionaryKeyPath.swift
Reading and writing to (possible) nested dictionaries for a path of keys, using a recursive approach
extension Dictionary {
public subscript(path string: Key, separator separator: String) -> Value? where Key == String {
get { self[path: string.split(separator: separator).map(String.init)] }
set { self[path: string.split(separator: separator).map(String.init)] = newValue }
}
public subscript(path path: Key...) -> Value? {
get { self[path: path] }
set { self[path: path] = newValue }
@Amzd
Amzd / StateObject.swift
Last active October 7, 2024 22:25
StateObject that works in iOS 13
import Combine
import PublishedObject // https://github.com/Amzd/PublishedObject
import SwiftUI
/// A property wrapper type that instantiates an observable object.
@propertyWrapper
public struct StateObject<ObjectType: ObservableObject>: DynamicProperty
where ObjectType.ObjectWillChangePublisher == ObservableObjectPublisher {
/// Wrapper that helps with initialising without actually having an ObservableObject yet
@Amzd
Amzd / DateRounding.swift
Created June 2, 2021 08:58 — forked from casperzandbergenyaacomm/DateRounding.swift
Rounding of date and time
import Foundation
extension Date {
/// Returns date where **-component** is rounded to its closest
/// multiple of **-amount**. Warning: month and day start at 1
/// so round(to: 6, .month) will either return month 1 or 7!
func round(to amount: Int, _ component: Calendar.Component) -> Date {
let cal = Calendar.current
var value = cal.component(component, from: self)