Skip to content

Instantly share code, notes, and snippets.

View LarsStegman's full-sized avatar

Lars Stegman LarsStegman

  • Allseas
  • The Netherlands
View GitHub Profile
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
@LarsStegman
LarsStegman / swiftui-non-resizing-scrollview.swift
Created October 18, 2019 15:08
Why doesn't the scrollview resize to fit all the contents. Right now, when a cell is tapped and resizes, the VStack size increases and starts falling outside the ScrollView. Shouldn't the ScrollView resize so all the elements stay inside the ScrollView
import SwiftUI
struct ImagePlaceholder: View {
var body: some View {
ZStack {
Rectangle()
.foregroundColor(Color(UIColor.systemGray3))
.aspectRatio(4/3, contentMode: .fill)
Image(systemName: "xmark.rectangle")
@LarsStegman
LarsStegman / Publisher+sequence.swift
Last active February 17, 2024 02:21
In the second beta of the Swift framework Combine there was no easy way to split a publisher output of type Sequence into separate values for every element in the sequence. This extension to Publisher adds an operator to do this.
import Combine
extension Publisher where Output: Sequence {
func sequence() -> Publishers.FlatMap<Publishers.Sequence<Self.Output, Self.Failure>, Self> {
self.flatMap { Publishers.Sequence(sequence: $0) }
}
}
let publisher = PassthroughSubject<Array<Int>, Never>()
publisher
@LarsStegman
LarsStegman / SortDescriptor.swift
Last active May 13, 2021 11:15
A Swifty sort descriptor
//
// SortDescriptor.swift
// MyTubePlayer
//
// Created by Lars Stegman on 04/12/2018.
// Copyright © 2018 Stegman. All rights reserved.
//
import Foundation
@LarsStegman
LarsStegman / ISO8601DateFormatter+TimeInterval.swift
Created November 18, 2018 17:52
ISO8601DateFormatter with time interval parsing
extension ISO8601DateFormatter {
/// Parses an ISO8601 time interval string
/// For example: P5DT19H6M15S represents 5 days 19 hours 6 minutes and 15 seconds.
/// PT4M5S represents 4 minutes and 5 seconds
/// M and S are mandatory.
///
/// - Parameter from: An ISO8601 interval string.
/// - Returns: The time interval in seconds that the string represents (if it's valid)
func interval(from: String) -> TimeInterval? {
let regex = try! NSRegularExpression(pattern: "P((?<d>[0-9]+)D)?T((?<h>[0-9]+)H)?((?<m>[0-9]+)M)((?<s>[0-9]+)S)")