Skip to content

Instantly share code, notes, and snippets.

View vibrazy's full-sized avatar

Daniel Hollis Tavares vibrazy

View GitHub Profile
@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 / 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 / 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
@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 / OptionSetSwiftUI.swift
Last active June 12, 2024 02:40
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 / 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 {
//
// 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 / Optional+Extensions.swift
Created June 28, 2016 22:28
Convenience extension on Optionals to return true or false if the collection is not empty and has elements
var userPreferences: [String]? = [""]
/// Type safe method to check if collection is nil and if not if it has values
func nilOrEmptyCollection<Collection where Collection: CollectionType>(collection: Collection?) -> Bool {
guard let collection = collection else { return true }
return collection.isEmpty
}
/// Extension on Options with constraint to collection type
extension Optional where Wrapped: CollectionType {