Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Hollis Tavares vibrazy

View GitHub Profile
@vibrazy
vibrazy / AnimatedState
Created Jun 1, 2021
Making it easier to deal with animations in SwiftUI
View AnimatedState
@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
Generate strongly typed PreviewDevice for SwiftUI
View PreviewDeviceExporter.swift
//
// 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
Toggled - Simpler way to deal with hardcoded ViewModifers values in SwiftUI
View Toggle.swift
struct ToggledExampleView_Previews: PreviewProvider {
static var previews: some View {
DebuggingToggledExampleView()
}
}
// MARK: - Toggled Source
protocol ToggleInterface {
associatedtype ValueType
@vibrazy
vibrazy / OptionSetSwiftUI.swift
Last active May 7, 2021
Using OptionSet to simplify your view state. Unify your states into 1
View OptionSetSwiftUI.swift
//
// 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
Created Jul 17, 2020
SwiftUI `ColorPicker` load and save values to disk using `AppStorage`
View ColorPickerStorageExample.swift
//
// ContentView.swift
// Shared
//
// Created by Dan Tavares on 17/07/2020.
//
import SwiftUI
struct ContentView: View {
@vibrazy
vibrazy / TilignTabView.swift
Created Jul 12, 2020
iOS 14, `ScrollViewReader` + `TabView`, rough around the edges but you get the idea.
View TilignTabView.swift
//
// TilingTabView.swift
//
//
// Created by Dan Tavares on 12/07/2020.
//
import SwiftUI
class State: ObservableObject {
View RootViewControllerIniOS14.swift
//
// 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 Jun 28, 2016
Convenience extension on Optionals to return true or false if the collection is not empty and has elements
View Optional+Extensions.swift
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 {
@vibrazy
vibrazy / NSUserDefaults+Extensions.swift
Created Apr 17, 2016
NSUserDefaults Save Generic Values
View NSUserDefaults+Extensions.swift
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)
}
}
/*
@vibrazy
vibrazy / UIStoryboardSegue+DestinationController.swift
Last active Apr 15, 2016
Generic UIStoryboardSegue Extension for Loading destinationViewController
View UIStoryboardSegue+DestinationController.swift
extension UIStoryboardSegue {
/*
Generic way of loading destinationViewController
Usage:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let controller = segue.destinationController("SegueName", type: CustomController.self) {
print(controller)
}
}
*/