This file contains 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
// A heterogeneous dictionary with strong types in Swift, https://oleb.net/2022/heterogeneous-dictionary/ | |
// Ole Begemann, April 2022 | |
/// A key in a `HeterogeneousDictionary`. | |
public protocol HeterogeneousDictionaryKey { | |
/// The "namespace" the key belongs to. Every `HeterogeneousDictionary` has its associated domain, | |
/// and only keys belonging to that domain can be stored in the dictionary. | |
associatedtype Domain | |
/// The type of the values that can be stored under this key in the dictionary. | |
associatedtype Value |
This file contains 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
node_modules |
This file contains 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
// This gist demonstrates how you can implement versioning for a Codable struct to support loading | |
// old serialized data after changing the structure. Notable features of this solution: | |
// | |
// * No need to make new properties optional, or to perform post-processing on the struct after | |
// loading in ordeer to populate missing values | |
// * No need to change the call site - from the outside this struct behaves just the same | |
// as if we had implemented codable directly in the normal way. | |
// * Versioning can be applied individually to parents or leaves in a larger tree of | |
// structs without affecting the other elements | |
// * This approach will work even if the original struct was not designed with versioning in mind |
This file contains 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
static const CGFloat kFontWeightEpsilon = FLT_EPSILON; | |
@implementation UIFont (CustomizedDynamicType) | |
+ (nonnull UIFont *)preferredFontWithDefaultSize:(CGFloat)size | |
textStyle:(nonnull UIFontTextStyle)textStyle { | |
return [self preferredFontWithDefaultSize:size | |
textStyle:textStyle | |
fontWeight:UIFontWeightRegular | |
italic:NO]; |
This file contains 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/zsh | |
cd "$(dirname "$0")/.." | |
if [[ -n "$CI" ]] || [[ $1 == "--fail-on-errors" ]] ; then | |
FAIL_ON_ERRORS=true | |
echo "Running in --fail-on-errors mode" | |
ERROR_START="" | |
COLOR_END="" | |
INFO_START="" |
This file contains 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/sh | |
# make sure you have imagemagick installed: brew install imagemagick | |
# your app_icons.sh file should have the correct permissions: run `chmod 775 app_icons.sh` in your terminal from where you put this file | |
# put your `my_icon.png` next to this file and run ./app_icons.sh to export your app icons | |
x=my_icon.png | |
y=${x%.*} | |
# delete the export directory so we start clean |
This file contains 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 SwiftUI | |
enum PreviewProviderMode: CaseIterable { | |
/// Use for a light appearance preview. | |
case lightMode | |
/// Use for a dark appearance preview. | |
case darkMode | |
This file contains 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
// Run any SwiftUI view as a Mac app. | |
import Cocoa | |
import SwiftUI | |
NSApplication.shared.run { | |
VStack { | |
Text("Hello, World") | |
.padding() | |
.background(Capsule().fill(Color.blue)) |
This file contains 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 | |
import LinkPresentation | |
class ViewController: UIViewController { | |
@IBOutlet weak var sharingButton: UIButton! | |
private var metaData: LPLinkMetadata = LPLinkMetadata() { | |
didSet { | |
DispatchQueue.main.async { |
NewerOlder