Skip to content

Instantly share code, notes, and snippets.

View vibrazy's full-sized avatar

Daniel Hollis Tavares vibrazy

View GitHub Profile
@vibrazy
vibrazy / unusedImages.sh
Created January 23, 2012 10:50
How to find unused images in an XCode project?
#!/bin/sh
# -------
# Usage sh unusedImages.sh (jpg|png|gif)
# -------
# Caveat
# 1 -
# NSString *imageName = [NSString stringWithFormat:@"image_%d.png", 1];
# This script would incorrectly list these images as unreferenced. For example, you might have
# This script will incorrectly think image_1.png is unreferenced.
# 2 - If you have a method, or variable with the same name as the image it won't pick it up
@vibrazy
vibrazy / UKPostcodeValidator.swift
Created March 20, 2016 11:30
Validate UK Postcodes in Swift 2.0
//
// UKPostcodeValidator.swift
// Medio
//
// Created by Daniel Tavares on 20/03/2016.
// Copyright © 2016 Daniel Tavares. All rights reserved.
// References: http://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive
// References: http://benscheirman.com/2014/06/regex-in-swift/
// Usage: UKPostcodeValidator.validate("W1D 5LH")
//
@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)
}
}
/*
//
// 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 / 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 / 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 / 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 / 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 / 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)