Skip to content

Instantly share code, notes, and snippets.

View brunogb's full-sized avatar

Bruno Bilescky brunogb

  • Hudl
  • London, UK
View GitHub Profile
struct LazyView<Content: View>: View {
let build: () -> Content
init(_ build: @autoclosure @escaping () -> Content) {
self.build = build
}
var body: Content {
build()
}
}
@fabiogiolito
fabiogiolito / FacebookReactions.swift
Last active August 11, 2022 15:25
Recreating Facebook Reactions with SwiftUI. Demo Video: https://twitter.com/fabiogiolito/status/1142226669471748096
//
// FacebookReactions.swift
//
// Created by Fabio Giolito on 10/06/2019.
// Follow me: https://twitter.com/fabiogiolito
//
import SwiftUI
struct FacebookReactions : View {
@chriseidhof
chriseidhof / swiftui.swift
Last active March 15, 2023 06:53
SwiftUI - iOS
import Combine
import CoreFoundation
import CoreGraphics
import CoreText
import Darwin
import Foundation
import SwiftUI
import UIKit
import os.log
import os
enum Demo {
case simple
case oneValue(Int)
case twoValues(String, Double)
case threeValues(one: Int, two: Float, [Int])
}
//: # Direct exposition in the enum
//: ## Sourcery Template
import PlaygroundSupport
import SwiftUI
extension View {
public func offset(by offset: CGPoint) -> Self.Modified<_OffsetEffect> {
self.offset(x: offset.x, y: offset.y)
}
}
struct LiveView : View {
@discardableResult
public func with<T>(_ value: T, _ builder: (T) -> Void) -> T {
builder(value)
return value
}
@discardableResult
public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T {
try builder(value)
return value
@douglashill
douglashill / KeyboardTableView.swift
Last active March 30, 2023 22:01
A UITableView that allows navigation and selection using a hardware keyboard.
// Douglas Hill, December 2018
// Made for https://douglashill.co/reading-app/
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit
import UIKit
/// A table view that allows navigation and selection using a hardware keyboard.
/// Only supports a single section.
class KeyboardTableView: UITableView {
// These properties may be set or overridden to provide discoverability titles for key commands.
@pmatanyc
pmatanyc / StickyHeaderScrollToSection
Created October 22, 2018 14:06
Scrolling to a section with a sticky header in UICollectionView
func scrollToSection(_ section: Int) {
if let collectionView = collectionView {
let indexPath = IndexPath(item: 0, section: section)
if
let attributes = collectionView.layoutAttributesForItem(at: indexPath),
let flowLayout = collectionView.collectionViewLayout as? FlowLayout
{
let headerHeight = flowLayout.headerReferenceSize
let topSectionInset = flowLayout.sectionInset.top
@chriseidhof
chriseidhof / Routing.swift
Last active May 13, 2018 06:06 — forked from gonzalonunez/Routing.swift
Routing Problem
import Foundation
struct Handler {
let handleJSON: (Data) throws -> Void
init<T: Decodable>(handler: @escaping (T) -> Void) {
handleJSON = { data in
let object = try JSONDecoder().decode(T.self, from: data)
handler(object)
}
@krzysztofzablocki
krzysztofzablocki / FindFinalClasses.swift
Last active August 22, 2021 12:12
Swift makes classes final if possible
#!/usr/bin/env bash
<% for type in types.classes { -%>
<%_ if type.attributes["final"] != nil || type.attributes["open"] != nil || types.based[type.name]?.isEmpty == false { continue } -%>
<%_ _%>git grep -lz 'class <%= type.name %>' | xargs -0 perl -i'' -pE "s/class <%= type.name %>(?=\s|:)/final class <%= type.name %>/g"
<% } %>