Skip to content

Instantly share code, notes, and snippets.

View seanlilmateus's full-sized avatar

Mateus seanlilmateus

View GitHub Profile
import Combine
extension URLSession {
/// Returns a publisher that wraps a URL session download task for a given
/// URL.
///
/// - Parameter url: The URL for which to create a download task.
/// - Returns: A publisher that wraps a download task for the URL.
@darrarski
darrarski / FetchedResultsPublisher.swift
Last active June 6, 2024 18:40
Swift-Combine-CoreData-Fetched-Results-Publisher
import Combine
import CoreData
public final class FetchedResultsPublisher
<ResultType>
: Publisher
where
ResultType: NSFetchRequestResult
{
//------------------------------------------------------------------------
// 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 {
@PaulWoodIII
PaulWoodIII / FetchedResultWidget.swift
Last active January 7, 2022 11:36
FetchRequest generation when sort state is changed
import SwiftUI
import CoreData
import Combine
struct NamesByYearView: View {
@EnvironmentObject var coreDataStack: CoreDataStack
@Environment(\.managedObjectContext) var managedObjectContext
@EnvironmentObject var importer: NameDatabaseImporter
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
import Combine
import Dispatch
/// Returns a subscriber that buffers up to `size` values before calling the given `handler`. The
/// subscriber will request more values from the upstream publisher once the `completion` closure
/// given to the `handler` is called.
func subscriber<Output, Failure>(size: Int, handler: @escaping (_ values: [Output], _ completion: @escaping () -> ()) -> ()) -> AnySubscriber<Output, Failure> {
@josephlord
josephlord / FetchedResultsControllerPublisher.swift
Created June 10, 2019 23:08
Making a Combine publisher from a FetchedResultsController
//
// FetchedResultsControllerPublisher.swift
// ListsModel
//
// Created by Joseph Lord on 09/06/2019.
// Copyright © 2019 Joseph Lord. All rights reserved.
//
import Foundation
import Combine
@alexito4
alexito4 / RemoteImage.swift
Last active August 19, 2020 15:32
Rough sketch of SwiftUI RemoteImage using AlamofireImage
import SwiftUI
import Combine
import AlamofireImage
let imageDownloader = ImageDownloader(
configuration: ImageDownloader.defaultURLSessionConfiguration(),
downloadPrioritization: .fifo,
maximumActiveDownloads: 4,
imageCache: AutoPurgingImageCache()
)
import SwiftUI
import Combine
class MyDatabase: BindableObject {
let didChange = PassthroughSubject<MyDatabase, Never>()
var contacts: [Contact] = [
Contact(id: 1, name: "Anna"), Contact(id: 2, name: "Beto"),
Contact(id: 3, name: "Jack"), Contact(id: 4, name: "Sam")
] {
@RoRoGadget
RoRoGadget / TouchInput.jsx
Last active June 8, 2019 12:41
SwiftUI4RN-TouchInput
import React, { Component } from 'react';
import { Alert, AppRegistry, Button, StyleSheet, View } from 'react-native';
export default class ButtonBasics extends Component {
_onPressButton() {
Alert.alert('You tapped the button!')
}
render() {
return (
//
// ContentView.swift
// TestingMoreSwiftUI
//
// Created by Chris Eidhof on 04.06.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
import Combine