Skip to content

Instantly share code, notes, and snippets.

@andreyz
andreyz / about.md
Created August 10, 2011 19:57 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
import UIKit
class TouchForwardingView: UIView {
var passthroughViews: [UIView] = []
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
guard let hitView = super.hitTest(point, with: event) else { return nil }
guard hitView == self else { return hitView }
@andreyz
andreyz / ManagedObjectChangesPublisher.swift
Created April 29, 2020 18:45 — forked from mjm/ManagedObjectChangesPublisher.swift
Observe changes to a Core Data fetch request with Combine
import Combine
import CoreData
extension NSManagedObjectContext {
func changesPublisher<Object: NSManagedObject>(for fetchRequest: NSFetchRequest<Object>)
-> ManagedObjectChangesPublisher<Object>
{
ManagedObjectChangesPublisher(fetchRequest: fetchRequest, context: self)
}
}
import SwiftUI
import WebKit
import Combine
class WebViewData: ObservableObject {
@Published var loading: Bool = false
@Published var scrollPercent: Float = 0
@Published var url: URL? = nil
@Published var urlBar: String = "https://nasa.gov"
@andreyz
andreyz / SwiftUI-TextView.swift
Created September 12, 2020 19:56 — forked from shaps80/SwiftUI-TextView.md
A SwiftUI view that wraps a UITextView but provides almost all functionality though modifiers and attempts to closely match the Text/TextField components.
/*
Notes:
The font modifier requires the following gist:
https://gist.github.com/shaps80/2d21b2ab92ea4fddd7b545d77a47024b
*/
//
// BottomSheetView.swift
//
// Created by Majid Jabrayilov
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
fileprivate enum Constants {
static let radius: CGFloat = 16
import Combine
import ComposableArchitecture
import UserNotifications
public struct UserNotificationClient {
public var add: (UNNotificationRequest) -> Effect<Void, Error>
public var delegate: Effect<DelegateEvent, Never>
public var getNotificationSettings: Effect<Notification.Settings, Never>
public var removeDeliveredNotificationsWithIdentifiers: ([String]) -> Effect<Never, Never>
public var removePendingNotificationRequestsWithIdentifiers: ([String]) -> Effect<Never, Never>
@andreyz
andreyz / Calendar.swift
Created November 3, 2020 14:38 — forked from mecid/Calendar.swift
SwiftUI Calendar view using LazyVGrid
import SwiftUI
fileprivate extension DateFormatter {
static var month: DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = "MMMM"
return formatter
}
static var monthAndYear: DateFormatter {
@andreyz
andreyz / LoadAndNavigateStyle.swift
Created November 22, 2022 22:42 — forked from tgrapperon/LoadAndNavigateStyle.swift
This gist demonstrates how to achieve a "Load and Navigate" navigation style using `NavigationStack` on iOS 16.
// This file is self contained and can be copy/pasted in place of the `ContentView.swift` in a default iOS 16/macOS 13 app.
import SwiftUI
struct ContentView: View {
@State var path: NavigationPath = .init()
@State var isLoading1: Bool = false
@State var isLoading2: Bool = false
@State var isLoading3: Bool = false
@andreyz
andreyz / Example.swift
Created December 6, 2022 13:15 — forked from IanKeen/Example.swift
PropertyWrapper: Ignore codable properties
struct Foo: Codable {
var name: String
@Ignore var foo: Int?
}
let model = Foo(name: "Ian", foo: 42)
let data = try! JSONEncoder().encode(model)
print(String(data: data, encoding: .utf8)!) // {"name":"Ian"}