Skip to content

Instantly share code, notes, and snippets.

View JasonCanCode's full-sized avatar

Jason JasonCanCode

View GitHub Profile
@m1entus
m1entus / CoreDataContextObserver.swift
Last active July 3, 2021 18:08
CoreDataContextObserver
//
// CoreDataContextWatcher.swift
// ContextWatcher
//
// Created by Michal Zaborowski on 10.05.2016.
// Copyright © 2016 Inspace Labs Sp z o. o. Spółka Komandytowa. All rights reserved.
//
import Foundation
import CoreData
@maciekish
maciekish / resetXcode.sh
Created August 10, 2016 10:13
Reset Xcode. Clean, clear module cache, Derived Data and Xcode Caches. You can thank me later.
#!/bin/bash
killall Xcode
xcrun -k
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
open /Applications/Xcode.app
@Edudjr
Edudjr / Dictionary+Extension.swift
Last active April 7, 2022 17:14
A Swift 3 extension for pretty-printing JSON (in swift: [String: Any])
// Dictionary/JSON Extension
// Pretty Print Json Objects
//
// Created by Domene on 10/02/17.
//
import Foundation
extension Dictionary where Key == String, Value == AnyObject {
func prettyPrint() -> String{
@JasonCanCode
JasonCanCode / Stopwatch.swift
Last active March 1, 2021 15:33
Helpful tool for printing to console when you are trying to figure out what is taking so long
class Stopwatch {
static let shared = Stopwatch()
let name: String
var shouldLogInRealTime: Bool = false
private var start: Date? {
willSet {
lap = newValue
}
@darrarski
darrarski / FormattedTextField.swift
Last active September 26, 2024 06:33
SwiftUI FormattedTextField - TextField with custom display/edit formatters
import SwiftUI
public struct FormattedTextField<Formatter: TextFieldFormatter>: View {
public init(_ title: String,
value: Binding<Formatter.Value>,
formatter: Formatter) {
self.title = title
self.value = value
self.formatter = formatter
}
@mattt
mattt / UIViewControllerPreview.swift
Last active December 3, 2024 07:42
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@JasonCanCode
JasonCanCode / Bindable.swift
Last active December 22, 2021 18:03
Give a property the power of a BehaviorRelay while preserving the object itself. The object can remain a constant property of a View Model and still be updated through Rx bindings.
import Foundation
import RxCocoa
import RxSwift
/// To persist updates through either the `wrappedValue` or `relay` while keeping the implementing property a value type.
private var cache = NSCache<AnyObject, AnyObject>()
@propertyWrapper
struct Bindable<Element> {
var projectedValue: Bindable { self }