Skip to content

Instantly share code, notes, and snippets.

View johnclayton's full-sized avatar

John Clayton johnclayton

View GitHub Profile
@carlosmcevilly
carlosmcevilly / apple-development-reference-links.md
Last active December 8, 2021 20:02
Device and software version reference links for development in Apple ecosystem
import SwiftUI
import WebKit
import Combine
class WebViewData: ObservableObject {
@Published var loading: Bool = false
@Published var scrollPercent: Float = 0
@Published var url: URL? = nil
@Published var urlBar: String = "https://nasa.gov"
@jordansinger
jordansinger / macOS.swift
Last active February 14, 2024 03:41
macOS SwiftUI Playgrounds code
import SwiftUI
import PlaygroundSupport
struct Desktop: View {
var body: some View {
ZStack {
// Image(uiImage: #imageLiteral(resourceName: "IMG_6281.JPG"))
Color(UIColor.systemBlue)
macOS()
}
@serbats
serbats / Combine+BaseAbstractions.swift
Last active September 13, 2020 20:52
Missing Apple Combine Operators: withLatestFrom, materialize, dematerialize
import Foundation
import Combine
// Base Abstraction Classes
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
protocol DownStreamHelperProtocol {
/// Helper for handling backpressure
/// DownstreamSubscription class use it as delegate for backpressure handling
associatedtype Input
@mjm
mjm / ManagedObjectChangesPublisher.swift
Created November 3, 2019 20:41
Observe changes to a Core Data fetch request with Combine
import Combine
import CoreData
extension NSManagedObjectContext {
func changesPublisher<Object: NSManagedObject>(for fetchRequest: NSFetchRequest<Object>)
-> ManagedObjectChangesPublisher<Object>
{
ManagedObjectChangesPublisher(fetchRequest: fetchRequest, context: self)
}
}
@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>(
@nyg
nyg / MemoryAddress.swift
Last active October 12, 2023 07:42
Get the memory address of both class and structure instances in Swift.
// https://stackoverflow.com/a/45777692/5536516
import Foundation
struct MemoryAddress<T>: CustomStringConvertible {
let intValue: Int
var description: String {
let length = 2 + 2 * MemoryLayout<UnsafeRawPointer>.size
@lattner
lattner / async_swift_proposal.md
Last active April 21, 2024 09:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@edasque
edasque / pre-commit
Last active December 22, 2020 15:10
pre-commit Git hook to JSONlint - place it in .git/hooks
#!/bin/sh
git diff-index -z --cached HEAD --name-only --diff-filter=ACMRTUXB |
xargs -0 -t -L1 /usr/local/bin/jsonlint -c;
if [ "$?" != "0" ]; then
echo "\nOne or more JSON file didn't pass jsonlint'ing.";
echo "Fix them before committing. If it is not possible to fix them all commit with the option --no-verify.";
exit 1;
@vlas-voloshin
vlas-voloshin / delete-duplicate-sims.rb
Last active April 18, 2024 19:04
Script for deleting duplicate iOS simulators and fixing simulators list in Xcode
#!/usr/bin/env ruby
# What is this for?
# This script fixes an issue appeared for some Xcode users where it would show long identifiers
# in the list of simulators instead of usual short names. This is caused by duplicate simulators
# being sometimes created after switching between Xcode versions, with the same
# device type + runtime pair occurring more than once in your list of available simulators.
# Instead of showing the same simulator name twice, Xcode defaults to simulator identifiers.
#
# What it does?