Skip to content

Instantly share code, notes, and snippets.

View abhi21git's full-sized avatar
:octocat:

Abhishek Maurya abhi21git

:octocat:
View GitHub Profile
@abhi21git
abhi21git / Extension+String.swift
Last active August 22, 2025 06:00
Access characters of string just like array
extension String {
subscript(_ i: Int) -> Character {
self[index(startIndex, offsetBy: i)]
}
}
@abhi21git
abhi21git / NumericTransion.swift
Created May 27, 2025 02:33
This code replicated iOS 18 lock screen clock text change animation.
extension View {
@ViewBuilder
func numericTransition(_ value: Double) -> some View {
if #available(iOS 17.0, *) {
contentTransition(.numericText(value: value))
.animation(.easeInOut(duration: 0.3), value: value)
} else {
transition(.opacity)
.animation(.easeInOut(duration: 0.2), value: value)
}
@abhi21git
abhi21git / AppConfig.swift
Last active December 11, 2025 13:54
Check for iOS 26 (can be modified for other versions too) and conditional glass effect to manage backward compatibility.
struct AppConfig {
static var isCompilerAtLeast62: Bool {
#if compiler(>=6.2)
return true
#else
return false
#endif
}
// This will only return true when built from Xcode 26 and for iOS 26 on other version it will return false.
@abhi21git
abhi21git / View+Extensions.swift
Created August 22, 2025 08:58
Use if condition on SwiftUIView without breaking method chaining
extension View {
@ViewBuilder
func `if`<TrueContent: View, FalseContent: View>(
_ condition: Bool,
@ViewBuilder _ trueTransform: (Self) -> TrueContent,
@ViewBuilder else falseTransform: (Self) -> FalseContent
) -> some View {
if condition {
trueTransform(self)
} else {