Skip to content

Instantly share code, notes, and snippets.

View brunogb's full-sized avatar

Bruno Bilescky brunogb

  • Hudl
  • London, UK
View GitHub Profile
@jordansinger
jordansinger / macOS.swift
Last active November 17, 2024 02:37
macOS SwiftUI Playgrounds code
import SwiftUI
import PlaygroundSupport
struct Desktop: View {
var body: some View {
ZStack {
// Image(uiImage: #imageLiteral(resourceName: "IMG_6281.JPG"))
Color(UIColor.systemBlue)
macOS()
}
@IanKeen
IanKeen / Convertible.swift
Created April 24, 2020 16:57
PropertyWrapper: Convert to/from raw type during decoding/encoding
import Foundation
public protocol CodingStrategy {
associatedtype Converted
associatedtype RawValue: Codable
static func toRaw(_ value: Converted) throws -> RawValue
static func toValue(_ raw: RawValue) throws -> Converted
}
@IanKeen
IanKeen / Default.swift
Last active July 4, 2024 14:55
PropertyWrapper: Decode default values. when they are `null`
import Foundation
public protocol DefaultValue {
associatedtype Value: Codable
static var value: Value { get }
}
@propertyWrapper
public struct Default<Default: DefaultValue>: Codable {
/// |                    World                 |
/// |------------------------------------------|
/// | Module A | Module B | Module C | Module D|
  1. World is a module
  2. World is aware of all modules.
  3. Modules aren't aware of World.
@danielmartin
danielmartin / BetterXcodeJumpToCounterpartSwift.org
Last active March 9, 2024 02:00
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"
@IanKeen
IanKeen / Derived.swift
Last active April 23, 2020 19:27
PropertyWrapper: Derived properties
@propertyWrapper
struct Derived<Instance, Value> {
var wrappedValue: Value {
get { fatalError() }
set { fatalError() }
}
private let getter: (Instance) -> Value
private let setter: (Instance, Value) -> Void
@IanKeen
IanKeen / Redraw.swift
Last active February 28, 2023 21:20
PropertyWrapper: Automatically redraw UIViews when a value changes
@propertyWrapper
struct Redraw<Value> {
var wrappedValue: Value
init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
}
static subscript<Instance: UIView>(
_enclosingInstance instance: Instance,
@chriseidhof
chriseidhof / collectionview.swift
Last active January 31, 2024 19:00
SwiftUI Flow Layout
//
// ContentView.swift
// DeleteMe
//
// Created by Chris Eidhof on 02.02.21.
//
import SwiftUI
/*
// https://twitter.com/krzyzanowskim/status/1149607371204784129
extension TimeInterval {
static func minutes(_ minutes: Int) -> TimeInterval {
return TimeInterval(seconds(60) * TimeInterval(minutes))
}
static func seconds(_ seconds: Int) -> TimeInterval {
return TimeInterval(seconds)
}
@vmanot
vmanot / PresentationLink2.swift
Created July 7, 2019 09:55
PresentationLink bug workaround for SwiftUI (Xcode b3)
extension UIApplication {
/// The top most view controller
static var topMostViewController: UIViewController? {
return UIApplication.shared.keyWindow?.rootViewController?.visibleViewController
}
}
extension UIViewController {
/// The visible view controller from a given view controller
var visibleViewController: UIViewController? {