Skip to content

Instantly share code, notes, and snippets.

@andreyz
andreyz / PageView.swift
Created February 28, 2023 15:13
An example of how to create a lazy loaded paged view in SwiftUI
import SwiftUI
/**
A container view that manages navigation between pages of content.
*/
public struct PageView<Content: View, Item: Hashable> {
public typealias ItemProvider = (Item) -> Item?
public typealias ViewProvider = (Item) -> Content
@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"}
@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 / 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 {
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>
//
// BottomSheetView.swift
//
// Created by Majid Jabrayilov
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
fileprivate enum Constants {
static let radius: CGFloat = 16
@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
*/
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 / 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)
}
}
[
{
"name": "Admir Rocks",
"category": "Featured",
"city": "Huddik",
"state": "Norrland",
"id": 1000,
"park": "Joshua Tree National Park",
"coordinates": {
"longitude": -116.166868,