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 SpriteKit | |
extension SKSpriteNode { | |
/// Initializes a textured sprite with a glow using an existing texture object. | |
convenience init(texture: SKTexture, glowRadius: CGFloat) { | |
self.init(texture: texture, color: .clear, size: texture.size()) | |
let glow: SKEffectNode = { | |
let glow = SKEffectNode() | |
glow.addChild(SKSpriteNode(texture: texture)) |
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
extension ClosedRange where Bound: BinaryFloatingPoint { | |
var random: Bound { | |
let ratio = Bound(arc4random_uniform(UInt32.max)) / Bound(UInt32.max - 1) | |
let offset = (upperBound - lowerBound) * ratio | |
return lowerBound + offset | |
} | |
} |
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
extension ClosedRange where Bound: BinaryInteger { | |
var random: Bound { | |
let offset = arc4random_uniform(UInt32(upperBound - lowerBound) + 1) | |
return lowerBound + Bound(offset) | |
} | |
} |
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
let randomDouble: Double = (-0.3...0.9).random | |
let randomCGFloat: CGFloat = (-0.9...0.9).random | |
let randomInt: Int = (-9...3).random | |
let randomUInt: UInt = (3...9).random |
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
enum Scene { | |
case home | |
case level(Int) | |
case levelSelection | |
} | |
extension Scene: RawRepresentable { | |
typealias RawValue = String | |
init?(rawValue: String) { |
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 Foundation | |
import ReactiveSwift | |
final class Pantry { | |
let jams = MutableProperty([Jam(flavour: .apple)]) | |
func add(jam: Jam) { | |
jams.value.append(jam) | |
} | |
} |
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
final class ViewController: UIViewController { | |
@IBOutlet weak var textView: UITextView! | |
let pantry = Pantry() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// SignalProducer runs the closure immediately. | |
pantry.jams.producer.startWithValues { [weak self] (jams) in |
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
final class Observable<T> { | |
init(_ value: T) { | |
self.value = value | |
} | |
var value: T { | |
didSet { | |
changeHandlers.forEach({ $0.handler(value) }) | |
} | |
} |
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
final class Pantry { | |
let jams = Observable([Jam(flavour: .apple)]) | |
func add(jam: Jam) { | |
jams.value.append(jam) | |
} | |
} | |
struct Jam { | |
enum Flavour: String { |
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
module CommonCrypto [system] { | |
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h" | |
export * | |
} |