Skip to content

Instantly share code, notes, and snippets.

@ajjames
ajjames / SwipeBackModifier.swift
Created April 25, 2025 04:57
adds swipe-left-to-dismiss
import SwiftUI
import UIKit
/// A ViewModifier that re-enables the default iOS edge-swipe back gesture in a SwiftUI NavigationStack.
struct SwipeBackModifier: ViewModifier {
func body(content: Content) -> some View {
content
.background(SwipeBackEnabler().frame(width: 0, height: 0).allowsHitTesting(false))
}
}
@ajjames
ajjames / BackgroundClearView.swift
Created April 24, 2025 17:41
Remove background from sheets
import SwiftUI
/// Usage:
/// .fullScreenOverlay(isPresented: $showAttachmentsMenu) {
/// SomeView()
/// .background(BackgroundClearView())
/// }
struct BackgroundClearView: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
let view = UIView()
@ajjames
ajjames / FullScreenPresenter.swift
Created April 24, 2025 17:36
FullScreenPresenter modifier
import SwiftUI
import UIKit
struct FullScreenPresenter<Overlay: View>: UIViewControllerRepresentable {
@Binding var isPresented: Bool
let overlay: () -> Overlay
func makeUIViewController(context: Context) -> UIViewController {
UIViewController() // container
}
@ajjames
ajjames / Logger.swift
Created August 2, 2021 20:05
Common Logger
import Foundation
import os.log
protocol Logger {
func error(_ error: String)
func warning(_ warning: String)
func event(_ event: String)
func message(_ message: String)
}
@ajjames
ajjames / Float+Extensions.swift
Created August 2, 2021 20:03
Common Float Extension
import Foundation
extension Float {
var toOneDecimalPlace: String { String(format: "%.1f", self) }
}
@ajjames
ajjames / DateFormatter+Extensions.swift
Created August 2, 2021 20:03
Common DateFormatter Extension
import Foundation
extension DateFormatter {
static let mediumDateTimeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.timeZone = TimeZone.current
formatter.dateStyle = .medium
formatter.timeStyle = .medium
return formatter
@ajjames
ajjames / DemoServicePlayground.swift
Last active August 4, 2021 16:52
Earthquake Service Demo
import Combine
import Foundation
// MARK: - Supporting Models: Once per codebase
enum HTTPMethod: String {
case delete
case get
case post
@ajjames
ajjames / OverlayView.swift
Created April 27, 2020 23:38
SwiftUI fullscreen overlay modifier
import SwiftUI
struct OverlayView<OverlayContent: View>: ViewModifier {
@Binding var isPresented: Bool
var modalContent: OverlayContent
var transition: AnyTransition = .move(edge: .bottom)
var animation: Animation = .easeInOut
func body(content: Content) -> some View {
@ajjames
ajjames / IfViews.swift
Created April 21, 2020 22:18
SwiftUI Helpers
import Combine
import SwiftUI
struct IfNotNil<Value, Content>: View where Content: View {
private let value: Value?
private let content: (Value) -> Content
init(_ value: Value?,
@ViewBuilder show content: @escaping (Value) -> Content) {
@ajjames
ajjames / ProofOfConceptTests.swift
Last active January 25, 2017 22:20
Proof-of-Concept Tests
import XCTest
import Realm
import RealmSwift
class ProofOfConceptTests: RealmTestCase {
// NOTE this is for objects with 1-to-1 relationships
func testUpdateAsset() {
// 1. make a full object
let city = City()