Skip to content

Instantly share code, notes, and snippets.

sunshinejr / AttributedString.swift
Last active November 24, 2022 16:14
Different approach to Attributed Strings in Swift.
View AttributedString.swift
import Foundation
import class UIKit.UIImage
struct AttributedString: ExpressibleByStringInterpolation {
enum Attribute: Hashable {
enum ImportanceLevel: String, Equatable {
case very
case enough
case important(ImportanceLevel = .enough)
sunshinejr / ClosureBarButtonItem.swift
Last active November 24, 2021 09:14
Setup for back/dismiss buttons in VCs, useful for MVVM+C pattern to finish coordinators or don't care about navigation controller and it's dismiss button (whether it's a back button or dismiss or w/e).
View ClosureBarButtonItem.swift
final class ClosureBarButtonItem: UIBarButtonItem {
private var customAction: (() -> Void)?
convenience init(barButtonSystemItem: UIBarButtonItem.SystemItem, action: (() -> Void)?) {
self.init(barButtonSystemItem: barButtonSystemItem, target: nil, action: nil) = self
self.action = #selector(didTap)
self.customAction = action
sunshinejr / Navigation.swift
Created February 26, 2020 10:57
SwiftUI Navigation stack
View Navigation.swift
struct NavigationStack: View {
@ObservedObject var viewModel: NavigationStackViewModel
var body: some View {
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
sunshinejr / Debounced.swift
Last active September 20, 2021 09:47
Swift Property wrapper for debouncing values
View Debounced.swift
public final class Debounced<T: Hashable>: BindingConvertible {
public let delay: Double
private var _value: T
private var timer: Timer? = nil
public var wrappedValue: T {
get {
return _value

Keybase proof

I hereby claim:

  • I am sunshinejr on github.
  • I am sunshinejr ( on keybase.
  • I have a public key ASC_9nKhKZwMWK4Ciutsh00FNk74FjRLf90QhujodtkmkQo

To claim this, I am signing this object:

sunshinejr / Defaults.swift
Last active September 13, 2020 15:30
Using NSUserDefaults in Swift 4.
View Defaults.swift
import Foundation
public let Defaults = UserDefaults.standard
open class DefaultsKeys {
fileprivate init() {}
open class DefaultsKey<ValueType>: DefaultsKeys {
public let _key: String
View Package.swift
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "Harvey",
products: [
name: "Harvey",
targets: ["Harvey"]),
View Package.swift
// swift-tools-version:4.0
View LazyTypeFull.swift
struct LazyType {
// Normal usage
lazy var soomethingLazy: String = {
return "Test lazy instance method"
// Lazy in statics
static var somethingLazy: String = {
return "Test lazy static method"
View LazyType.swift
struct LazyType {
lazy var soomethingLazy: String = {
return "Test lazy instance method"