Skip to content

Instantly share code, notes, and snippets.

View vibrazy's full-sized avatar

Daniel Hollis Tavares vibrazy

View GitHub Profile
@vibrazy
vibrazy / OptionSetSwiftUI.swift
Last active May 31, 2023 09:06
Using OptionSet to simplify your view state. Unify your states into 1
//
// Created by Daniel Tavares on 07/05/2021.
//
import SwiftUI
// MARK: - OptionsSet
// Blog post https://dev.to/vibrazy/easy-swiftui-view-bindings-using-optionset-and-sourcery-4edb
protocol OptionsBinding {}
@vibrazy
vibrazy / AnimatedState
Created June 1, 2021 09:38
Making it easier to deal with animations in SwiftUI
@propertyWrapper
struct AnimatedState<Value> : DynamicProperty {
let storage: State<Value>
let animation: Animation?
init(
value: Value,
animation: Animation? = nil
) {
self.storage = State<Value>(initialValue: value)
@vibrazy
vibrazy / ColorPickerStorageExample.swift
Last active January 28, 2023 18:19
SwiftUI `ColorPicker` load and save values to disk using `AppStorage`
//
// ContentView.swift
// Shared
//
// Created by Dan Tavares on 01/07/2022.
// More Info: https://nilcoalescing.com/blog/EncodeAndDecodeSwiftUIColor/
import SwiftUI
#if os(iOS)
@vibrazy
vibrazy / TilignTabView.swift
Created July 12, 2020 16:01
iOS 14, `ScrollViewReader` + `TabView`, rough around the edges but you get the idea.
//
// TilingTabView.swift
//
//
// Created by Dan Tavares on 12/07/2020.
//
import SwiftUI
class State: ObservableObject {
@vibrazy
vibrazy / strategyPattern.swift
Created August 5, 2022 08:08
Strategy Pattern
import UIKit
import Combine
// MADE UP CODE
typealias Package = Int
struct Offerings {
var monthtly: Package?
var annual: Package?
var lifetime: Package?
@vibrazy
vibrazy / HelloAnimationView.swift
Created June 29, 2022 20:55
Hello Animation View - SwiftUI
//
// HelloAnimationView.swift
// SwiftUIBiteSize
//
// Created by Dan Tavares on 29/06/2022.
//
import SwiftUI
struct HelloAnimationView: View {
@vibrazy
vibrazy / Toggle.swift
Created May 10, 2021 10:56
Toggled - Simpler way to deal with hardcoded ViewModifers values in SwiftUI
struct ToggledExampleView_Previews: PreviewProvider {
static var previews: some View {
DebuggingToggledExampleView()
}
}
// MARK: - Toggled Source
protocol ToggleInterface {
associatedtype ValueType
@vibrazy
vibrazy / PreviewDeviceExporter.swift
Created May 17, 2021 08:33
Generate strongly typed PreviewDevice for SwiftUI
//
// main.swift
// PreviewDeviceExporter
//
// Created by Dan Tavares on 13/05/2021.
// https://github.com/JohnSundell/Files
// https://github.com/JohnSundell/ShellOut.git
// Packages used
//
// Created by Dan Tavares on 10/07/2020.
//
import SwiftUI
struct WindowKey: EnvironmentKey {
static let defaultValue: UIWindow? = {
guard
let firstScene = UIApplication.shared.connectedScenes.first,
@vibrazy
vibrazy / NSUserDefaults+Extensions.swift
Created April 17, 2016 15:18
NSUserDefaults Save Generic Values
extension NSUserDefaults {
static func getSavedValue<T>(key: String) -> T? {
return NSUserDefaults.standardUserDefaults().objectForKey(key) as? T
}
static func setSavedValue<T>(value: T, key: String) {
NSUserDefaults.standardUserDefaults().setObject(value as? AnyObject, forKey: key)
}
}
/*