Author: Chris Lattner
/// This is a simple example of Neumorphism applied to buttons in SwiftUI | |
/// As seen on https://twitter.com/dev_jac/status/1228575575171723264 | |
/// This should work straight out of the box, no other files are required | |
import SwiftUI | |
extension Color { | |
static let mainColor = Color(red: 224/255, green: 229/255, blue: 236/255) | |
static let mainColorActive = Color(red: 220/255, green: 225/255, blue: 232/255) | |
static let grayShadow = Color(red: 163/255, green: 177/255, blue: 198/255) |
import UIKit | |
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
@IBOutlet weak var tableView: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
NSLayoutConstraint.activate([ | |
tableView.topAnchor.constraint(equalTo: view.topAnchor), |
import Foundation | |
struct EquatableValueSequence<T: Equatable> { | |
static func ==(lhs: EquatableValueSequence<T>, rhs: T) -> Bool { | |
return lhs.values.contains(rhs) | |
} | |
static func ==(lhs: T, rhs: EquatableValueSequence<T>) -> Bool { | |
return rhs == lhs | |
} |
- Proposal: SE-XXXX
- Authors: Chris Lattner, Joe Groff
Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.
This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.
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,
import Foundation | |
protocol Settings { | |
subscript(key: String) -> AnyObject? { get nonmutating set } | |
} | |
struct Defaults: Settings { | |
typealias Set = (String, AnyObject?) -> Void | |
typealias Get = (String) -> AnyObject? | |
import Cocoa | |
import MASShortcut | |
func pow() { | |
let rect = NSScreen.mainScreen()?.frame | |
let window = NSWindow(contentRect: rect!, styleMask: NSBorderlessWindowMask, backing: .Buffered, `defer`: false) | |
window.backgroundColor = NSColor.clearColor() | |
window.opaque = false | |
window.alphaValue = 1 | |
window.makeKeyAndOrderFront(NSApplication.sharedApplication()) |
// Draw a sine curve with a fill | |
let centerY = frame.height / 2 // find the vertical center | |
let steps = 200 // Divide the curve into steps | |
let stepX = frame.width / CGFloat(steps) // find the horizontal step distance | |
// Make a path | |
let path = UIBezierPath() | |
path.moveToPoint(CGPoint(x: 0, y: centerY)) | |
// Loop and draw steps in straingt line segments |
// Draw a sine curve with a fill | |
let centerY = frame.height / 2 // find the vertical center | |
let steps = 200 // Divide the curve into steps | |
let stepX = frame.width / CGFloat(steps) // find the horizontal step distance | |
// Make a path | |
let path = UIBezierPath() | |
// Start in the lower left corner | |
path.moveToPoint(CGPoint(x: 0, y: frame.height)) |