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 | |
public struct FormattedTextField<Formatter: TextFieldFormatter>: View { | |
public init(_ title: String, | |
value: Binding<Formatter.Value>, | |
formatter: Formatter) { | |
self.title = title | |
self.value = value | |
self.formatter = formatter | |
} |
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 Random { | |
static func within<B: protocol<Comparable, ForwardIndexType>>(range: ClosedInterval<B>) -> B { | |
let inclusiveDistance = range.start.distanceTo(range.end).successor() | |
let randomAdvance = B.Distance(arc4random_uniform(UInt32(inclusiveDistance.toIntMax())).toIntMax()) | |
return range.start.advancedBy(randomAdvance) | |
} | |
static func within(range: ClosedInterval<Float>) -> Float { | |
return (range.end - range.start) * Float(Float(arc4random()) / Float(UInt32.max)) + range.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
// Easter calculation in swift after Anonymous Gregorian algorithm | |
// Also known as Meeus/Jones/Butcher algorithm | |
import Foundation | |
func easter(Y : Int) -> NSDate { | |
let a = Y % 19 | |
let b = Int(floor(Double(Y) / 100)) | |
let c = Y % 100 | |
let d = Int(floor(Double(b) / 4)) |