Skip to content

Instantly share code, notes, and snippets.

// Algorithm from https://en.wikipedia.org/wiki/Permuted_congruential_generator
struct PRNG: RandomNumberGenerator {
var state: UInt64 = 0x4d595df4d0f33173
let multiplier: UInt64 = 6364136223846793005
let increment: UInt64 = 1442695040888963407
init(seed: UInt64) {
state = seed &+ increment
import Combine
struct Location {
}
//protocol WeatherService {
// func getTemperature(location: Location) -> AnyPublisher<Double, Error>
//}
//
//
// ContentView.swift
// EditDemo
//
// Created by Ray Fix on 7/25/20.
//
import SwiftUI
// This is a hack!
func hideKeyboard() {
//
// ContentView.swift
// Ring
//
// Created by Ray Fix on 6/20/20.
// Copyright © 2020 Ray Fix. All rights reserved.
//
import SwiftUI
@rayfix
rayfix / SetCard.swift
Created June 14, 2020 00:01
SetCard abstraction
func combinations<S1: Sequence, S2: Sequence>(_ sequence1: S1, _ sequence2: S2) -> AnySequence<(S1.Element, S2.Element)> {
AnySequence(
sequence1.lazy.flatMap { element1 in
sequence2.lazy.map { element2 in
(element1, element2)
}
}
)
}
@rayfix
rayfix / Observe.swift
Created May 23, 2020 19:22
Some example of using observable object
import SwiftUI
import Combine
final class ViewModel: ObservableObject {
var subs: Set<AnyCancellable> = []
// For some reason this does not work!
init() {
import SwiftUI
extension View {
func printType() -> Self {
print(type(of: self))
return self
}
}
// Need to make a key; all it needs is a default value.
@rayfix
rayfix / PublishedViewModel.swift
Last active May 16, 2020 22:26
Some SwiftUI/Combine examples
//
// ContentView.swift
// Pub
//
// Created by Ray Fix on 5/16/20.
// Copyright © 2020 Ray Fix. All rights reserved.
//
import SwiftUI
import Combine
@rayfix
rayfix / draggable.swift
Created May 9, 2020 19:48
make views draggable
//
// ContentView.swift
//
// Created by Ray Fix on 5/9/20.
// Copyright © 2020 Ray Fix. All rights reserved.
//
import SwiftUI
struct ContentView: View {
@rayfix
rayfix / SwiftUIChartsExample.swift
Last active May 2, 2020 18:59
John James demonstrated using SwiftUI charts
// Load the Swift Package: https://github.com/AppPear/ChartView
import SwiftUI
import SwiftUICharts
struct ContentView: View {
@State var tabIndex:Int = 0