Skip to content

Instantly share code, notes, and snippets.

View donnywals's full-sized avatar

Donny Wals donnywals

View GitHub Profile
import SwiftUI
struct ContentView: View {
@State private var exercises: [Exercise] = Exercise.sample
var body: some View {
NavigationSplitView(sidebar: {
ExercisesList(exercises: exercises)
}, detail: {
ExerciseDetail(exercise: exercises.first!)
})
import UIKit
import SwiftUI
// Hacky workaround, use at your own risk and all that
struct BottomSheetPresenter<Content>: UIViewRepresentable where Content: View{
let label: String
let content: Content
let detents: [UISheetPresentationController.Detent]
init(_ label: String, detents: [UISheetPresentationController.Detent], @ViewBuilder content: () -> Content) {
enum Status: Decodable {
case completed, inProgress
case other(String)
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(String.self)
switch value {
case "completed": self = .completed
import Foundation
enum TargetEnum: Codable {
case first(SomeObject)
case second(OtherObject)
enum CodingKeys: CodingKey {
case type
}
import Foundation
let json = """
{
"userId": 0,
"name": "Donny"
}
""".data(using: .utf8)!
let fakeSQLite = """
import Foundation
let json = """
{
"userId": 0,
"name": "Donny"
}
""".data(using: .utf8)!
struct User: Codable {
#!/bin/sh
# make sure you have imagemagick installed: brew install imagemagick
# your app_icons.sh file should have the correct permissions: run `chmod 775 app_icons.sh` in your terminal from where you put this file
# put your `my_icon.png` next to this file and run ./app_icons.sh to export your app icons
x=my_icon.png
y=${x%.*}
# delete the export directory so we start clean
/*
Here's our goal:
let localDataStore = UserDataStore()
let remoteDataStore = UserApi()
let dataStore = CacheBackedDataStore(localDataStore, remoteDataStore)
dataStore.fetch(userID) { result in
// handle result
}
class UploadTaskPublisher {
typealias UploadProgress = (bytesSent: Int64, expectedTotalBytes: Int64)
typealias ProgressSubject = CurrentValueSubject<UploadProgress, Never>
typealias CompletionSubject = PassthroughSubject<URLSession.DataTaskPublisher.Output, URLSession.DataTaskPublisher.Failure>
var progress = ProgressSubject((0, 0))
var completion = CompletionSubject()
}
import Foundation
@propertyWrapper
struct YMD {
var wrappedValue: Date?
}
extension YMD: Codable {
func encode(to encoder: Encoder) throws {
if let date = self.wrappedValue {