Skip to content

Instantly share code, notes, and snippets.

@twzurkan
twzurkan / Heap.swift
Last active March 17, 2024 21:26
Swift Heap/PriorityQueue
/// This is a simple Heap implementation which can be used as a priority queue.
class Heap<T:Comparable> {
typealias HeapComparator<T:Comparable> = (_ l:T,_ r:T) -> Bool
var heap = [T]()
var count:Int {
get {
heap.count
}
}
@barabashd
barabashd / TCA_README_UKR.md
Last active May 12, 2024 23:59
TCA_README_UKR.md

The Composable Architecture

CI Slack

The Composable Architecture (скорочено TCA) - це бібліотека для побудови додатків у послідовному та зрозумілому підході з урахуванням композиції, тестування та ергономіки. Вона може бути в

@AlexKobachiJP
AlexKobachiJP / XcodeCommand
Last active June 1, 2024 20:26
Sort file and package references in an Xcode project.
// Copyright © 2023 Alex Kovács. All rights reserved.
import ArgumentParser
import Foundation
import PathKit
import XcodeProj
// See below for `MainCommand` skeleton.
extension MainCommand {
struct XcodeCommand: ParsableCommand {
@DougGregor
DougGregor / macros.md
Last active October 24, 2023 16:42
A possible vision for macros in Swift

A Possible Vision for Macros in Swift

As Swift evolves, it gains new language features and capabilities. There are different categories of features: some fill in gaps, taking existing syntax that is not permitted and giving it a semantics that fit well with the existing language, with features like conditional conformance or allowing existential values for protocols with Self or associated type requirements. Others introduce new capabilities or paradigms to the language, such as the addition of concurrency or comprehensive reflection.

There is another large category of language features that provide syntactic sugar to eliminate common boilerplate, taking something that can be written out in long-form and making it more concise. Such features don't technically add any expressive power to the language, because you can always write the long-form version, but their effect can be transformational if it enables use cases that would otherwise have been unwieldy. The synthesis of Codable conformances, for ex

enum MediaLibrary {}
// MARK: - ViewModel
extension MediaLibrary {
final class ViewModel {
let progressCompletionThreshold: Double
var zoomPosition: ZoomPosition,
assetsCount: Int,
_zoomStatus: ZoomType?
@swiftui-lab
swiftui-lab / showSizes.swift
Last active May 11, 2024 03:54
A debugging modifier for SwiftUI views (showSizes)
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: Implementation of the showSizes() debugging modifier
// blog article: https://swiftui-lab.com/layout-protocol-part-2
import SwiftUI
struct MeasureExample: View {
var body: some View {
VStack {
@IanKeen
IanKeen / Abstraction.swift
Created August 16, 2022 17:41
TCA Scoping Abstraction
// MARK: - TCAView
public protocol TCAView: View where Body == WithViewStore<ScopedState, ScopedAction, Content> {
associatedtype ViewState
associatedtype ViewAction
associatedtype ScopedState
associatedtype ScopedAction
associatedtype Content
@dduan
dduan / SwiftChartPong.swift
Last active May 30, 2024 11:20
Pong Game implemented with Swift Charts.
import SwiftUI
import Charts
import Combine
import Foundation
final class GameState: ObservableObject {
struct Player {
var position: Int
var halfSize: Int = 150
enum AsyncError: Error {
case finishedWithoutValue
}
extension AnyPublisher {
func async() async throws -> Output {
try await withCheckedThrowingContinuation { continuation in
var cancellable: AnyCancellable?
var finishedWithoutValue = true
cancellable = first()
extension AnyPublisher {
func async() async throws -> Output {
try await withCheckedThrowingContinuation { continuation in
var cancellable: AnyCancellable?
cancellable = first()
.sink { result in
switch result {
case .finished:
break