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
// Figuring out how CoreStore's monitor/observer mechanism works was a painful | |
// experience. This is a working example of how to use list object observers and | |
// single object observers. You'll need CoreStore, of course, to run this. | |
// Instantiate a Database object and call the .go() method. The reason for the | |
// Timers is that I wanted to make sure the code would run in asynchronous pieces, | |
// rather than all on one execution thread, to more-or-less simulate mouse | |
// clicks in a real app. | |
// | |
// https://github.com/JohnEstropia/CoreStore -- don't get me wrong, it was | |
// worth the pain. But with any luck this example will spare you some headaches. |
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
// See how to use it at the bottom of this file | |
// Helper struct for sequenceDiff | |
public struct SequenceDiff<T1, T2> { | |
public let common: [(T1, T2)] | |
public let removed: [T1] | |
public let inserted: [T2] | |
public init(common: [(T1, T2)] = [], removed: [T1] = [], inserted: [T2] = []) { | |
self.common = common | |
self.removed = removed |
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
// With gratitude to David Harris http://davidharris.io/ | |
// for his article on making generic factories. I might keep some of my hair. | |
// | |
// http://davidharris.io/ios/swift/2018/03/19/generic-factory.html | |
import Foundation | |
open class Builder<DependencyType> { | |
public typealias DependencyCreator = () -> DependencyType |
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
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the "Software"), | |
// to deal in the Software without restriction, including without limitation | |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
// and/or sell copies of the Software, and to permit persons to whom the | |
// Software is furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in | |
// all copies or substantial portions of the Software. |
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 SpriteKit | |
import GameplayKit | |
class GameScene: SKScene { | |
var box1: SKShapeNode? | |
var box2: SKShapeNode? | |
override func didMove(to view: SKView) { | |
let b1 = SKShapeNode(circleOfRadius: 50.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 Foundation | |
import SpriteKit | |
func getColorName(_ color: NSColor) -> String { | |
switch color { | |
case .black: return "black" | |
case .white: return "white" | |
case .gray: return "gray" | |
case .red: return "red" | |
case .green: return "green" |
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 SpriteKit | |
import GameplayKit | |
class GameScene: SKScene { | |
static var shared: GameScene? | |
var frameCount = 0 | |
var bigSprite: SKSpriteNode? | |
var bigSpriteIsSetup = false | |
var spriteTexture: SKTexture? |
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
struct ProtoOrder<T> { | |
var quantity: T | |
init(_ quantity: T) { self.quantity = quantity } | |
} | |
protocol ItemProtocol { | |
associatedtype HowCounted: Numeric | |
typealias Order = ProtoOrder<HowCounted> |
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 CoreGraphics | |
/// Arithmetic extensions for CGPoint, CGSize, and CGVector. | |
/// All of the operators +, -, *, /, and unary minus are supported. Where | |
/// applicable, operators can be applied to point/size/vector + point/size/vector, | |
/// as well as point/size/vector + CGFloat and CGFloat + point/size/vector. | |
protocol Overload2D { | |
/// Really for internal use, but publicly available so the unit tests can use them. | |
var a: CGFloat { get set } | |
var b: CGFloat { get set } |
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
// We are a way for the cosmos to know itself. -- C. Sagan | |
import SwiftUI | |
class ChildState: ObservableObject { | |
@Published var childData = 0 | |
} | |
struct Parent: View { | |
@State var parentData = 0 |
OlderNewer