Skip to content

Instantly share code, notes, and snippets.

@johnkodes
johnkodes / flowlayout.swift
Created March 14, 2024 06:18
SwiftUI Flow Layout
/// https://onmyway133.com/posts/how-to-make-tag-flow-layout-using-layout-protocol-in-swiftui/
struct FlowLayout: Layout {
struct Result {
var size: CGSize
var cells: [Cell]
}
struct Cell {
var frame: CGRect
}
# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# All available actions: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Actions.md
# can also be listed using the `fastlane actions` command
# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`
# If you want to automatically update fastlane if a new version is available:
# update_fastlane
@johnkodes
johnkodes / RelativeSizeLayout.swift
Created March 25, 2023 11:45 — forked from ole/RelativeSizeLayout.swift
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.
@johnkodes
johnkodes / Sequence+unique.swift
Created March 7, 2023 13:25
Unique elements from Sequence
extension Sequence {
/// Returns an array containing, in order, the first instances of
/// elements of the sequence that compare equally for the keyPath.
func unique<T: Hashable>(for keyPath: KeyPath<Element, T>) -> [Element] {
var unique = Set<T>()
return filter { unique.insert($0[keyPath: keyPath]).inserted }
}
}
extension RangeReplaceableCollection {
@johnkodes
johnkodes / Remove whitespace
Created March 2, 2023 13:39
Remove whitespace from folder
find . -not \( -name .git -prune \) -type f -print0 | LANG=C LC_CTYPE=C xargs -0 sed -i '' -E "s/[[:space:]]*$//"