Skip to content

Instantly share code, notes, and snippets.

View mbuchetics's full-sized avatar

Matthias Buchetics mbuchetics

View GitHub Profile
@ole
ole / RelativeSizeLayout.swift
Last active March 24, 2024 22:24
A SwiftUI layout and modifier for working with relative sizes ("50 % of your container"). https://oleb.net/2023/swiftui-relative-size/
import SwiftUI
extension View {
/// Proposes a percentage of its received proposed size to `self`.
///
/// This modifier multiplies the proposed size it receives from its parent
/// with the given factors for width and height.
///
/// If the parent proposes `nil` or `.infinity` to us in any dimension,
/// we’ll forward these values to our child view unchanged.
// A URLSession extension that fetches data from a URL and decodes to some Decodable type.
// Usage: let user = try await URLSession.shared.decode(UserData.self, from: someURL)
// Note: this requires Swift 5.5.
extension URLSession {
func decode<T: Decodable>(
_ type: T.Type = T.self,
from url: URL,
keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys,
dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .deferredToData,
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate
@truizlop
truizlop / Wave.swift
Created September 10, 2020 14:41
Wave animation using SwiftUI
import SwiftUI
let LINE_LENGTH: Double = 500.0
let N = 720
let LINES = 18
let WAVES: Double = 18.0
let WAVE_HEIGHT: Double = 20
let SPACING: Double = 27.0
let CURL_AMOUNT: Double = 12.0
@adamzarn
adamzarn / add-swift-support
Last active November 30, 2023 20:17
A bash script to add the SwiftSupport folder to an .ipa to resolve the ITMS-90426: Invalid Swift Support error.
#!/bin/bash
# Usage:
# 1. Copy the script into a text editor and save it with no extension
# 2. Make it executable like so: chmod +x path/to/script
# 3. Run it from the Terminal in one of two ways:
# * path/to/script ipa_path="path/to/ipa" archive_path="path/to/xcarchive"
# * path/to/script ipa_path="path/to/ipa" toolchain_path="path/to/toolchain"
@mecid
mecid / Calendar.swift
Last active June 24, 2024 13:17
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)
@WiesnerPeti
WiesnerPeti / DebuggerCheck.swift
Created January 3, 2020 11:06
iOS Swift Check if debugger is attached
func debuggerAttached() -> Bool {
var process_info:kinfo_proc = kinfo_proc()
var process_info_len:size_t = MemoryLayout<kinfo_proc>.size
var process_info_mib:[Int32] = [
CTL_KERN,
KERN_PROC,
KERN_PROC_PID,
getpid()
];
@masamichiueta
masamichiueta / Color.swift
Created October 21, 2019 09:25
Bridge UIColor system color to SwiftUI Color
import UIKit
import SwiftUI
extension Color {
static var label: Color {
return Color(UIColor.label)
}
static var secondaryLabel: Color {
//
// ContentView.swift
// navigation
//
// Created by Thomas Ricouard on 13/10/2019.
// Copyright © 2019 Thomas Ricouard. All rights reserved.
//
import SwiftUI
@mattgallagher
mattgallagher / AppDelegate.swift
Last active May 18, 2022 17:42
Animated circle views in SwiftUI and AppKit/CoreAnimation
//
// AppDelegate.swift
// SwiftUITestApp
//
// Created by Matt Gallagher on 4/6/24.
// Copyright © 2019 Matt Gallagher. All rights reserved.
//
import Cocoa
import SwiftUI
@Thomvis
Thomvis / SwiftUI-Circular.swift
Last active August 4, 2021 21:41
Rough attempt at creating a container view that lays out its children in a circle #SwiftUI
struct ContentView: View {
@State var count: Int = 3
var body: some View {
return NavigationView {
VStack(spacing: 50) {
HStack {
Button(action: { self.count += 1 }) {
Text("Add")
}