Skip to content

Instantly share code, notes, and snippets.

View sebj's full-sized avatar

Seb Jachec sebj

View GitHub Profile
@sebj
sebj / AnyInsettableShape.swift
Last active September 1, 2023 09:36
AnyInsettableShape
/// A type-erased shape that is able to inset itself to produce another shape.
///
/// See: [AnyShape](https://developer.apple.com/documentation/swiftui/anyshape), [InsettableShape](https://developer.apple.com/documentation/swiftui/insettableshape)
struct AnyInsettableShape: InsettableShape {
private let _sizeThatFits: (ProposedViewSize) -> CGSize
private let _path: (CGRect) -> Path
private let _inset: (CGFloat) -> AnyInsettableShape
init<S>(_ shape: S) where S : InsettableShape {
@sebj
sebj / ContentView.swift
Created July 22, 2023 20:01
Example: define dynamic colors via SwiftUI's ShapeStyle on iOS 17
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.foregroundStyle(.customBackground)
}
}
#Preview {
@sebj
sebj / ChildCombinations.swift
Last active August 8, 2023 10:08
A container that produces different combinations of children as part of a given `Layout`, by incrementally dropping the lowest priority child. See https://movingparts.io/variadic-views-in-swiftui & https://chris.eidhof.nl/post/variadic-views/
import SwiftUI
struct ContentView: View {
var body: some View {
HStack(spacing: 20) {
ViewThatFits(in: .vertical) {
ChildCombinations(in: VStackLayout(spacing: 0)) {
TestSquare(color: .red)
.combinationPriority(2)
@sebj
sebj / Guide.md
Last active April 11, 2024 00:08
Add a scene delegate back to a SwiftUI Project

Define an application delegate

See also: UIApplicationDelegate documentation

// AppDelegate.swift
@UIApplicationMain
final class AppDelegate: NSObject, UIApplicationDelegate {

    func application(
        _ application: UIApplication,
@sebj
sebj / View+CornerRadius.swift
Created November 3, 2022 12:02
Round specific corners of a view/shape
extension View {
/// Clips this view to its bounding frame, with the specified corner radius for the given corners.
///
/// By default, a view's bounding frame only affects its layout, so any
/// content that extends beyond the edges of the frame remains visible. Use
/// `cornerRadius(_:corners:)` to hide any content that extends beyond
/// these edges while applying a corner radius.
///
/// - Returns: A view that clips this view to its bounding frame with the
@sebj
sebj / games.graphql
Created July 24, 2021 10:50
PlayStation Game Library GraphQL Queries/Mutations 2021-07-24
query backwardCompatibility($titleIds: String) {
backwardsCompatibilityRetrieve(titleIds: $titleIds) {
titleBackwardsCompatibilityList {
titleId,
category
}
}
}
query downloadProgress($entitlementId: ID, $duid: ID) {
@sebj
sebj / Dictionary+MapKeys.swift
Created January 22, 2021 23:27
Dictionary Extension: Map Keys
extension Dictionary {
/// Returns a new dictionary containing the keys of this dictionary transformed
/// by the given closure with the existing values.
///
/// - Parameter transform: A closure that transforms a key. `transform`
/// accepts each key of the dictionary as its parameter and returns a
/// transformed key of the same or of a different type.
/// - Returns: A dictionary containing the transformed keys and values of
/// this dictionary.
///
@sebj
sebj / Levenshtein
Last active August 29, 2015 14:23 — forked from krstnfx/Levenshtein
Levenshtein to get edit distance between two strings (ignores newlines, but counts spaces)
- (float)compareString:(NSString *)originalString withString:(NSString *)comparisonString {
// Normalize strings
[originalString stringByTrimmingCharactersInSet:NSCharacterSet.newlineCharacterSet];
[comparisonString stringByTrimmingCharactersInSet:NSCharacterSet.newlineCharacterSet];
originalString = originalString.lowercaseString;
comparisonString = comparisonString.lowercaseString;
// Step 1
NSInteger k, i, j, cost, * d, distance;