For every type T
in Swift, there is an associated metatype T.Type
.
Let's try to write a generic function like staticSizeof
. We will only consider its declaration; implementation is trivial and unimportant here.
Out first try would be:
Sources include, but not limited to:
There are so many great GIFs out there and I want to have copies of them. Twitter makes that harder than it should be by converting them to MP4 and not providing access to the source material. To make it easier, I made a bash pipeline that takes a tweet URL and a filename, extracts the MP4 from that tweet and uses ffmpeg to convert back to GIF.
brew install ffmpeg
apt install ffmpeg
# Collection of one line text art (◕‿◕✿) | |
Collection of emojis and one line text art like (╯°□°)╯︵ ┻━┻ 🤗 | |
ּבּ_בּ | |
טּ_טּ | |
כּ‗כּ | |
לּ_לּ | |
מּ_מּ | |
סּ_סּ |
Foundation offers a Thread class, internally based on pthread
, that can be used to create new threads and execute closures.
// Detaches a new thread and uses the specified selector as the thread entry point.
Thread.detachNewThreadSelector(selector: Selector>, toTarget: Any, with: Any)
// Subclass
class MyThread: Thread {
@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 |
// | |
// ContentView.swift | |
// Scribe | |
// | |
// Created by Cyril Zakka on 7/21/19. | |
// Copyright © 2019 Cyril Zakka. All rights reserved. | |
// | |
import SwiftUI | |
struct ContentView: View { |
// Original article here: https://fivestars.blog/swiftui/swiftui-share-layout-information.html | |
import SwiftUI | |
extension View { | |
func readSize(onChange: @escaping (CGSize) -> Void) -> some View { | |
background( | |
GeometryReader { geometryProxy in | |
Color.clear | |
.preference(key: SizePreferenceKey.self, value: geometryProxy.size) |