Skip to content

Instantly share code, notes, and snippets.

View pd95's full-sized avatar

Philipp pd95

  • Freelance Software Engineer
  • Zurich, Switzerland
View GitHub Profile
@pd95
pd95 / ContentView.swift
Created November 9, 2024 13:46
Bottom view not moving while interactive keyboard dismissal is ongong
import SwiftUI
struct MessageInput: View {
@State private var text = ""
@FocusState private var isFocused: Bool
var body: some View {
HStack {
TextField("Enter your message…", text: $text)
.textFieldStyle(.roundedBorder)
@pd95
pd95 / NumberTextField.swift
Created March 28, 2022 08:27
An implementation of a `NumberTextField` based on `TextField` which should work with any `BinaryInteger` based type.
import SwiftUI
struct NumberTextField<NumberType: BinaryInteger>: View {
private let title: LocalizedStringKey
private let range: ClosedRange<NumberType>?
private let format: IntegerFormatStyle<NumberType>
@Binding private var value: NumberType?
@State private var valueString: String = ""
@pd95
pd95 / DemoApp.swift
Last active March 26, 2023 09:04
A `DocumentGroup` demo app (based on the Xcode iOS app template with Core Data enabled) illustrating wrapping `UIManagedDocument` using SwiftUI `ReferenceFileDocument`
/*
How to use the content of this gist:
- Create a new iOS app using the "App" template,
set the product name to "Demo", use "SwiftUI" for interface and enable Core Data.
- go to the apps target (=click the Project "Demo" and select "Demo" as under "Targets")
- select the "Info" tab
@pd95
pd95 / ContentView.swift
Created July 1, 2020 21:04
Illustrate Memory leak in Publisher.replaceError
//
// ContentView.swift
// Bug-Combine-Leak
//
import Combine
import SwiftUI
final class Store: ObservableObject {
struct User: Codable {
@pd95
pd95 / Export-HEVC.swift
Created June 2, 2020 22:25
Swift Playground code showing how to convert a video from H264 (in my case) to HEVC/H265 using AVFoundation
import AVFoundation
// Get test video from bundle
let url = Bundle.main.url(forResource: "test", withExtension: "mp4")!
let anAsset = AVURLAsset(url: url)
// get properties of video track
let track = anAsset.tracks(withMediaType: AVMediaType.video).first!
let size = track.naturalSize.applying(track.preferredTransform)
let frameSize = CGSize(width: abs(size.width), height: abs(size.height))
@pd95
pd95 / ContentView.swift
Last active September 9, 2022 09:02
InstaFilter main logic for CoreImage filter application
//
// ContentView.swift
// Project13
//
// Created by Paul Hudson on 17/02/2020.
// Copyright © 2020 Paul Hudson. All rights reserved.
//
import CoreImage
import CoreImage.CIFilterBuiltins
@pd95
pd95 / AppIcons.command
Last active December 28, 2022 20:56
A ZSH command file to produce the various PNG files required for iOS and macOS app Icons using `sips` (scriptable image processing system) available on any macOS. The resulting PNGs in the "AppIcons" folder can then be dragged into Xcode's `Assets.xcassets` onto a placeholder for an AppIcon.
#!/bin/zsh
# Shell Script to create all relevant icons from an high resolution artwork
if [ "x$1" != "x" -a -f "$1" ] ; then
INPUT=$1
else
INPUT="Artwork.png"
fi
if [ ! -f "$INPUT" ]; then