Skip to content

Instantly share code, notes, and snippets.

//Orginal code from: https://gist.github.com/mecid/f8859ea4bdbd02cf5d440d58e936faec
//I just made some modification in appearnce, show monthly navigator and weekdays.
import SwiftUI
struct ContentView: View {
@Environment(\.calendar) var calendar
private var year: DateInterval {
calendar.dateInterval(of: .month, for: Date())!
@mecid
mecid / Calendar.swift
Last active July 1, 2024 07:14
SwiftUI Calendar view using LazyVGrid
import SwiftUI
extension Calendar {
func generateDates(
inside interval: DateInterval,
matching components: DateComponents
) -> [Date] {
var dates: [Date] = []
dates.append(interval.start)
//
// ContentView.swift
//
// Created by Chris Eidhof on 20.04.20.
// Copyright © 2020 objc.io. All rights reserved.
//
import SwiftUI
import UIKit
@ole
ole / combine-urlsession.swift
Last active November 7, 2019 02:53
Combine with URLSession.dataTaskPublisher
// https://twitter.com/BelleBCooper/status/1192173933983715328
import Combine
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
/// JSON format:
///
@darrarski
darrarski / FormattedTextField.swift
Last active May 25, 2024 10:14
SwiftUI FormattedTextField - TextField with custom display/edit formatters
import SwiftUI
public struct FormattedTextField<Formatter: TextFieldFormatter>: View {
public init(_ title: String,
value: Binding<Formatter.Value>,
formatter: Formatter) {
self.title = title
self.value = value
self.formatter = formatter
}
@darrarski
darrarski / NumberField.swift
Last active October 18, 2023 18:10
SwiftUI NumberField - TextField with custom display/edit number formatters
import SwiftUI
public struct NumberField: View {
public init(_ title: String,
value: Binding<NSNumber?>,
decorator: @escaping (String) -> String = { $0 }) {
self.title = title
self.value = value
let formatter = NumberFormatter()
@chriseidhof
chriseidhof / collectionview.swift
Last active January 31, 2024 19:00
SwiftUI Flow Layout
//
// ContentView.swift
// DeleteMe
//
// Created by Chris Eidhof on 02.02.21.
//
import SwiftUI
/*
@unnamedd
unnamedd / TextFieldTyped.swift
Last active October 9, 2022 21:05
[SwiftUI] Wrapping a UITextField into SwiftUI to use different keyboards, e.g: UIKeyboardType.twitter, UIKeyboardType.numbersAndPunctuation
// Created by Thiago Holanda on 22.06.19.
// twitter.com/tholanda
import SwiftUI
struct ContainerView: View {
@State var decimal = ""
@State var twitter = ""
@State var url = ""
@State var search = ""
@sledsworth
sledsworth / NutrientModel.swift
Last active April 17, 2021 16:48
Generic Animated Progress Bar in SwiftUI
import Foundation
import UIKit
import SwiftUI
import Combine
class NutrientModel: Progressable {
var willChange = PassthroughSubject<BaseNutrient, Never>()
var id = UUID.init()
var name: String
@broadwaylamb
broadwaylamb / combine.swift
Last active September 27, 2020 10:59
Combine Generated Interface
import Darwin
/// A type-erasing cancellable object that executes a provided closure when canceled.
///
/// Subscriber implementations can use this type to provide a “cancellation token” that makes it possible for a caller to cancel a publisher, but not to use the ``Subscription`` object to request items.
///
/// An ``AnyCancellable`` instance automatically calls ``Cancellable/cancel()`` when deinitialized.
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
final public class AnyCancellable : Cancellable, Hashable {