This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DumpExample | |
// This SwiftUI View explores use of the dump() function for manipulating the debugging display | |
// of large, structured data. | |
// | |
// Created by Quinn McHenry on 2/17/22. | |
import SwiftUI | |
struct ContentView: View { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension NSDataAsset { | |
/// Load a data asset from a catalog and try decoding it to a specific Decodable type | |
/// - Returns: An optional instance of type T decoded from the named data asset | |
/// Usage: `NSDataAsset.decode(DocodableThing.self, asset: "my thing")` | |
public static func decode<T>(_ type: T.Type, asset name: String) -> T? where T: Decodable { | |
guard let asset = Self(name: name) else { return nil } | |
return try? JSONDecoder().decode(T.self, from: asset.data) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
select branch in $(git branch | cut -c3-) | |
do | |
git switch $branch | |
exit | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// String+Bundle.swift | |
// PlanetSwift | |
// | |
// Created by Brad Bambara on 1/13/15. | |
// Copyright (c) 2015 Small Planet. All rights reserved. | |
// | |
import Foundation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
,ad8888ba, 88 88 | |
d8"' `"8b ,d 88 "" | |
d8' `8b 88 88 | |
88 88 MM88MMM 88,dPPYba, ,adPPYba, 8b,dPPYba, 8b db d8 88 ,adPPYba, ,adPPYba, | |
88 88 88 88P' "8a a8P_____88 88P' "Y8 `8b d88b d8' 88 I8[ "" a8P_____88 | |
Y8, ,8P 88 88 88 8PP""""""" 88 `8b d8'`8b d8' 88 `"Y8ba, 8PP""""""" | |
Y8a. .a8P 88, 88 88 "8b, ,aa 88 `8bd8' `8bd8' 88 aa ]8I "8b, ,aa | |
`"Y8888Y"' "Y888 88 88 `"Ybbd8"' 88 YP YP 88 `"YbbdP"' `"Ybbd8"' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift enums cannot be declared with a rawValue if they have associated values | |
// like good ol' Amargasaurus has. Using String(describing: dino) on a case with | |
// associated also includes the values, but works fine on unassociated cases. | |
// Mirror(reflecting: dino) can extract the name of an associated case, but is | |
// nil for unassociated cases. Our hero ?? swoops in to save the day! | |
enum Sauropoda { | |
case Amargasaurus(things: Int64, hasOtherThing: Bool?) | |
case Antetonitrus | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// with Then | |
let label = UILabel().then { | |
$0.textAlignment = .center | |
$0.textColor = .black | |
$0.text = "Hello, World!" | |
} | |
// just Swift | |
let label: UILabel() = { | |
$0.textAlignment = .center |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/25329186/safe-bounds-checked-array-lookup-in-swift-through-optional-bindings/30593673#30593673 | |
extension CollectionType { | |
/// Returns the element at the specified index iff it is within bounds, otherwise nil. | |
subscript (safe index: Index) -> Generator.Element? { | |
return indices.contains(index) ? self[index] : nil | |
} | |
} | |
// Usage: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift 2.x | |
public class func GCDDelay(delayAmount:Float, block:(Void->Void)) { | |
dispatch_after(dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), | |
Int64(delayAmount * Float(NSEC_PER_SEC))), dispatch_get_main_queue(), block) | |
} | |
GCDDelay(0.5) { UIApplication.sharedApplication.openURL(url) } | |
// Swift 3 |
NewerOlder