Skip to content

Instantly share code, notes, and snippets.

View filimo's full-sized avatar

VictorK filimo

View GitHub Profile
@darrarski
darrarski / Publisher+Materialize.swift
Created September 9, 2019 07:35
Simple extension to materialize Combine publishers (helpful when unit testing)
import Combine
extension Publisher {
func materialize() -> Result<[Output], Failure> {
var values = [Output]()
var result: Result<[Output], Failure>!
let semaphore = DispatchSemaphore(value: 0)
let subscription = sink(receiveCompletion: { completion in
switch completion {
@darrarski
darrarski / IfLet.swift
Last active January 7, 2021 13:15
SwiftUI IfLet helper functions
import SwiftUI
func IfLet<T, ThenOut: View>(
_ value: T?,
then: (T) -> ThenOut
) -> some View {
ViewBuilder.buildIf(value.map { then($0) })
}
func IfLet<T, ThenOut: View, ElseOut: View>(
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {
@unnamedd
unnamedd / MacEditorTextView.swift
Last active May 26, 2024 17:49
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@erikbasargin
erikbasargin / Publisher+CustomDecoder.swift
Last active July 9, 2019 20:52
Fix Publisher.decode for JSONDecoder and TopLevelDecoder 🛠
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Publisher where Output == URLSession.DataTaskPublisher.Output {
public func decode<Item, Coder>(type: Item.Type, decoder: Coder) -> Publishers.TryMap<Self, Item> where Item: Decodable, Coder: TopLevelDecoder, Coder.Input == Data {
return tryMap { try decoder.decode(type, from: $0.data) }
}
}
@stinger
stinger / CombineFetcherAndDecoder.swift
Last active February 17, 2024 02:07
Combine - fetching and decoding JSON data
import Foundation
import Combine
enum APIError: Error, LocalizedError {
case unknown, apiError(reason: String), parserError(reason: String)
var errorDescription: String? {
switch self {
case .unknown:
return "Unknown error"
@stinger
stinger / CombineFetcher.swift
Last active January 28, 2023 18:07
Combine - fetching data using URLSession publishers
import Foundation
import Combine
enum APIError: Error, LocalizedError {
case unknown, apiError(reason: String)
var errorDescription: String? {
switch self {
case .unknown:
return "Unknown error"
import Combine
// When wrapping a value, we take advantage of the setter
// to feed a PassthroughSubject
@propertyWrapper
struct Published<T> {
private var innerValue: T
private let innerSubject = PassthroughSubject<T, Never>()
@harishgonnabattula
harishgonnabattula / WWDC.json
Created August 25, 2018 20:34
WWDC 2015-2018 Video urls and summary
[
{"url": "https://devstreaming-cdn.apple.com/videos/wwdc/2018/236mwbxbxjfsvns4jan/236/236_hd_avspeechsynthesizer_making_ios_talk.mp4?dl=1", "title": "AVSpeechSynthesizer: Making iOS Talk", "summary": "Speech can enhance the audio experience of your app, whether you are generating spoken feedback for accessibility, or providing critical information beyond simple alerts or notifications. AVSpeechSynthesizer produces synthesized speech from text and allows you to control and monitor the progress of ongoing speech. Learn the ins and outs of AVSpeechSynthesizer and how to add computer-generated speech output to your app."},
{"url": "https://devstreaming-cdn.apple.com/videos/wwdc/2018/405bjty1j94taqv8ii/405/405_hd_measuring_performance_using_logging.mp4?dl=1", "title": "Measuring Performance Using Logging", "summary": "Learn how to use signposts and logging to measure performance. Understand how the Points of Interest instrument can be used to examine logged data. Get an introduction into creating and using custo
@shaps80
shaps80 / 1. UserDefaults+Key.swift
Last active September 25, 2020 08:29
Adds a Swift extension to make UserDefaults more consistent to work with.
//
// UserDefaults.swift
//
// Created by Shaps Benkau on 24/05/2018.
// Copyright © 2018 152percent Ltd. All rights reserved.
//
import Foundation
#if os(iOS)