Skip to content

Instantly share code, notes, and snippets.

Avatar

Philipp pd95

  • Freelance iOS Developer
  • Zurich, Switzerland
  • Twitter @pd959
View GitHub Profile
@pd95
pd95 / NumberTextField.swift
Created Mar 28, 2022
An implementation of a `NumberTextField` based on `TextField` which should work with any `BinaryInteger` based type.
View NumberTextField.swift
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 Apr 19, 2022
A `DocumentGroup` demo app (based on the Xcode iOS app template with Core Data enabled) illustrating wrapping `UIManagedDocument` using SwiftUI `ReferenceFileDocument`
View DemoApp.swift
/*
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 Jul 1, 2020
Illustrate Memory leak in Publisher.replaceError
View ContentView.swift
//
// ContentView.swift
// Bug-Combine-Leak
//
import Combine
import SwiftUI
final class Store: ObservableObject {
struct User: Codable {
@pd95
pd95 / Export-HEVC.swift
Created Jun 2, 2020
Swift Playground code showing how to convert a video from H264 (in my case) to HEVC/H265 using AVFoundation
View Export-HEVC.swift
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 Sep 9, 2022
InstaFilter main logic for CoreImage filter application
View ContentView.swift
//
// 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 Nov 12, 2022
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.
View AppIcons.command
#!/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