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
@resultBuilder | |
public struct ArrayBuilder<Element> { | |
public static func buildPartialBlock(first: Element?) -> [Element] { first.map { [$0] } ?? [] } | |
public static func buildPartialBlock(first: [Element]?) -> [Element] { first ?? [] } | |
public static func buildPartialBlock(first: [Element?]?) -> [Element] { (first ?? []).compactMap { $0 } } | |
public static func buildPartialBlock(accumulated: [Element], next: Element?) -> [Element] { accumulated + (next.map { [$0] } ?? []) } | |
public static func buildPartialBlock(accumulated: [Element], next: [Element]?) -> [Element] { accumulated + (next ?? []) } | |
public static func buildPartialBlock(accumulated: [Element], next: [Element?]?) -> [Element] { accumulated + (next ?? []).compactMap { $0 } } | |
// Empty Case |
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 FuzzySearch { | |
struct Match { | |
let weight: Double | |
let indexes: [String.Index] | |
let string: String | |
} | |
struct Option: OptionSet { |
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 SwiftUI | |
import AVKit | |
// NOTE: be careful when use as it has state problem. | |
struct LoopPlayerView: View { | |
let player: AVQueuePlayer | |
let playerItem: AVPlayerItem | |
let configuration: PlayerView.Configuration |
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 SwiftUI | |
struct VisualEffectView: UIViewRepresentable { | |
let visualEffectViewConfiguration: (UIVisualEffectView) -> Void | |
init( | |
visualEffectViewConfiguration: @escaping (UIVisualEffectView) -> Void = { _ in } | |
) { | |
self.visualEffectViewConfiguration = visualEffectViewConfiguration | |
} |
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 SwiftUI | |
struct Carousel<Data: RandomAccessCollection, Content: View>: View where Data.Index: Hashable { | |
let data: Data | |
let content: (Data.Element) -> Content | |
let shouldFitWidth: Bool | |
let shouldFitHeight: Bool |
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
actor MyActor { | |
var currentTask: Task<Void, Error>? | |
@discardableResult | |
func run<Value>( | |
_ action: @Sendable (_ actor: isolated MyActor) async throws -> Value | |
) async rethrows -> Value { | |
try await action(self) | |
} | |
} |
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 | |
import Moya | |
struct AsyncRequestError: Error { | |
// TODO: add Description | |
} | |
extension MoyaProvider { | |
// method #1 - using AsyncThrowingStream | |
func request(_ target: Target) async throws -> Response { |
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 AProtocol { | |
func callAsFunction() | |
} | |
class AClass: AProtocol { | |
func callAsFunction() { print("hi there") } | |
} | |
let a: any AProtocol = AClass() | |
a() // prints "hi there" |
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 SwiftUI | |
#Preview { | |
struct SampleView: View { | |
@State var presentsSheet = false | |
var body: some View { | |
Button { presentsSheet.toggle() } label: { Text("Toggle Sheet") } | |
.uiKitSheet( | |
isPresented: $presentsSheet, |
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 | |
extension Publisher { | |
func makeHot() -> AnyPublisher<Output, Failure> { | |
let subject = PassthroughSubject<Void, Never>() | |
let publisher = map(Result.success) | |
.catch { Just(.failure($0)) } | |
.prefix(untilOutputFrom: subject) | |
.makeConnectable() | |
let connection = publisher.connect() |
NewerOlder