struct User: Equatable { | |
var firstName: String | |
var lastName: String | |
} | |
@main | |
struct MyApp: App { | |
@State var value = User(firstName: "", lastName: "") | |
@State var showEdit = false |
// | |
// ContentView.swift | |
// TryGeometryReader | |
// | |
// Created by satoutakeshi on 2019/12/07. | |
// Copyright © 2019 satoutakeshi. Licensed under MIT. | |
// | |
import SwiftUI |
// create context with no upfront defaultValue | |
// without having to do undefined check all the time | |
function createCtx<A>() { | |
const ctx = React.createContext<A | undefined>(undefined) | |
function useCtx() { | |
const c = React.useContext(ctx) | |
if (!c) throw new Error("useCtx must be inside a Provider with a value") | |
return c | |
} | |
return [useCtx, ctx.Provider] as const |
1. Create a new xcode project | |
- You can skip this if you're adding the playground to an existing project | |
2. File > Save as workspace - save workspace in project folder | |
- You can skip this if you're adding the playground to an existing workspace | |
3. File > Playground - create new playground in project folder | |
4. Drag playground in at the _workspace_ level (root item, i.e. _not_ under the project) | |
5. Add a new Framework to your project (I usually name mine something like 'PlaygroundKit') | |
- You don't need to include tests | |
- Choose 'None' for Enbed in Application | |
6. Make all project files you want to be accessible to the playground are members of the new target |
State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?
There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.
Here I present a composable pattern for pure state machiness with effects,
JavaScriptCore is a built-in iOS library that enables you to use JavaScript in apps alongside Objective-C and Swift. It lets developers read JavaScript from a string, execute it from Objective-C or Swift, and share data structures and functions across languages. We JavaScriptCore to share code between Web and iOS.
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
// | |
// Trie.swift | |
// SceneTest | |
// | |
// Created by Greg Titus on 6/7/14. | |
// Copyright (c) 2014 The Omni Group. All rights reserved. | |
// | |
// This is essentially the same data structure as OFTrie in OmniFoundation, except that the OmniFoundation version is mutable and ephemeral, | |
// and this version is immutable and persistent. Every time you add a string to the trie, it replaces all the nodes along the string's path |