View closure.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// struct for printing out instance address | |
struct MemoryAddress<T>: CustomStringConvertible { | |
let intValue: Int | |
var description: String { | |
let length = 2 + 2 * MemoryLayout<UnsafeRawPointer>.size | |
return String(format: "%0\(length)p", intValue) | |
} |
View asyncstream.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol FooDelegate: AnyObject { | |
func didReceive(value: Int) | |
func didOpen() | |
func didClose() | |
} | |
class Foo { | |
weak var delegate: FooDelegate? | |
func open() { |
View saerv.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ComposableArchitecture | |
import SwiftUI | |
struct <#Name#>State: Equatable {} | |
enum <#Name#>Action: Equatable {} | |
struct <#Name#>Environment {} | |
extension <#Name#>Environment { |
View DelegatePublisher.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import CombineExt // Check this implementation: https://github.com/CombineCommunity/CombineExt/blob/main/Sources/Operators/Create.swift | |
import CoreBluetooth | |
// Client to generate target delegate publisher | |
// Learned from https://github.com/pointfreeco/composable-core-location/blob/main/Sources/ComposableCoreLocation/Live.swift | |
struct PeripheralClient { | |
enum Action: Equatable { | |
case didUptateName |
View crash.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol P { | |
associatedtype A | |
associatedtype B | |
} | |
protocol Q: P {} | |
extension Q where A == Int { | |
typealias B = Int | |
} |
View Either.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Either<A, B> { | |
case left(A) | |
case right(B) | |
} | |
extension Either: Decodable where A: Decodable, B: Decodable { | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
if let a = try? container.decode(A.self) { | |
self = .left(a) |
View bytes_handler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using UInt8 as Byte | |
typealias Byte = UInt8 | |
enum Bit: Int { | |
case zero, one | |
} | |
extension Data { | |
var bytes: [Byte] { | |
var byteArray = [UInt8](repeating: 0, count: self.count) | |
self.copyBytes(to: &byteArray, count: self.count) |
View Kind.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kind of type | |
public enum Kind { | |
case `struct` | |
case `enum` | |
case optional | |
case opaque | |
case tuple | |
case function | |
case existential | |
case metatype |
View View.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Collapsable<Content: View>: View { | |
@State var collapsed: Bool = true | |
let content: () -> Content | |
init(@ViewBuilder content: @escapin () -> Content) { | |
self.content = content | |
} | |
var body: some View { | |
VStack { |
View filter_keyPath.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
var bar: Int | |
var overThreshold: Bool { | |
bar > 5 | |
} | |
} | |
let fooArray: [Foo] = ... | |
let filtered = fooArray.filter(\.overThreshold) |
NewerOlder