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 | |
// Model + controller: | |
struct NamedTimer: Identifiable, Equatable { | |
let id = UUID() | |
var name: String | |
var seconds = 0 | |
} |
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 | |
struct Item: Equatable, Identifiable { | |
let id = UUID() | |
var title: String | |
var isFavorite = false | |
} | |
@MainActor class ListViewModel: ObservableObject { | |
@Published private(set) var items: [Item] = [] |
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 | |
/// View that observes its position within a given coordinate space, | |
/// and assigns that position to the specified Binding. | |
struct PositionObservingView<Content: View>: View { | |
var coordinateSpace: CoordinateSpace | |
@Binding var position: CGPoint | |
@ViewBuilder var content: () -> Content | |
var body: some View { |
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 fun little game written in SwiftUI | |
// Copyright (c) John Sundell 2020, MIT license. | |
// This is a hacky implementation written just for fun. | |
// It's only verified to work on iPhones in portrait mode. | |
import SwiftUI | |
final class GameController: ObservableObject { | |
@Published var plane = GameObject.plane() | |
@Published private(set) var clouds = [GameObject]() |
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
#!/usr/bin/env bash | |
# Put this file in /usr/local/bin and then run chmod +x on it to make it executable | |
command=$1 | |
shift | |
case $command in | |
"init" ) | |
swift package init "$@" |
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
#!/usr/bin/env bash | |
# If run without a name, open any current repo | |
if [ -z "$1" ]; then | |
URL=$(git remote get-url origin) | |
URL=${URL/"git@github.com:"/"https://github.com/"} | |
URL=${URL/".git"/""} | |
open $URL | |
else | |
open "https://github.com/$1" |
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/bash | |
ITERATION=1 | |
EXTENSION="mp4" | |
FILENAME="$HOME/Desktop/Simulator Recording.$EXTENSION" | |
while [ -e "$FILENAME" ] | |
do | |
ITERATION=$((ITERATION+1)) | |
FILENAME="$HOME/Desktop/Simulator Recording $ITERATION.$EXTENSION" |
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
extension Optional { | |
struct RequireError: Error, CustomStringConvertible { | |
var description: String { | |
return "Required optional value was nil" | |
} | |
} | |
func require(orThrow errorClosure: @autoclosure () -> Error = RequireError()) throws -> Wrapped { | |
switch self { | |
case .some(let 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
// Either put this in a separate file that you only include in your macOS target | |
// or wrap the code in #if os(macOS) / #endif | |
import Cocoa | |
// Step 1: Typealias UIImage to NSImage | |
typealias UIImage = NSImage | |
// Step 2: You might want to add these APIs that UIImage has but NSImage doesn't. | |
extension NSImage { |
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
target 'MyTarget' do | |
use_frameworks! | |
# Post installation script that enables the Swift 4.2 compiler's | |
# legacy 4.1 mode for 4.2-incompatible pods | |
post_install do |installer| | |
incompatiblePods = ['PodA', 'PodB'] | |
installer.pods_project.targets.each do |target| | |
if incompatiblePods.include? target.name |
NewerOlder