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 GameplayKit | |
struct Die: Equatable { | |
public static var roll: Int { | |
if #available(iOS 9, *) { | |
let d6 = GKRandomDistribution.d6() | |
return (d6.nextInt()) | |
} | |
else { | |
let d6 = 6 |
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
// Generic deck management, doesn't care about its contents | |
protocol DeckDelegate: AnyObject { | |
associatedtype Element | |
var size: Int { get } | |
var isEmpty: Bool { get } | |
var cards:[Element] { get set } | |
func push(_ element: Element) | |
func pop() -> Element? | |
func shuffle() |
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 | |
// Simple cash handling with error throwing | |
internal protocol WalletDelegate { | |
func didCredit(_amount: Int) -> Bool | |
func didDebit(_amount: Int) -> Bool | |
} |
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
// | |
// WalletInteractor.swift | |
// | |
// Tries to use an Interactor to fashion off work | |
// against the Wallet model via delegates | |
// | |
// Tries to be single responsibility (?) | |
// | |
// Created by AD on 21/06/2020. | |
// Copyright © 2020 AD. All rights reserved. |
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
// Swift 3 | |
struct Deck { | |
var name: String | |
} | |
// usual way; | |
var decks : [Deck] = [Deck]() | |
for idx in 1...10 { | |
decks.append( Deck.init(name: "#\(idx)") ) |