- Reference semantics
- Immutability
- Value semantics
- Value types in practice
- Mixing value types and reference types
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
extension Sequence { | |
func reduce<A>(_ initial: A, combine: (inout A, Iterator.Element) -> ()) -> A { | |
var result = initial | |
for element in self { | |
combine(&result, element) | |
} | |
return result | |
} | |
} |
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
// Original article here: https://www.fivestars.blog/code/redacted-custom-effects.html | |
import SwiftUI | |
// MARK: Step 1: Create RedactionReason | |
public enum RedactionReason { | |
case placeholder | |
case confidential |
Author: Chris Lattner
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 ContentView: View { | |
var body: some View { | |
VStack{ | |
Label("Hello Label", systemImage: "sun.min") | |
.font(.system(.title, design: .rounded)) | |
Label("Title only label", systemImage: "sun.min") | |
.font(.system(.title, design: .rounded)) |
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
// Run any SwiftUI view as a Mac app. | |
import Cocoa | |
import SwiftUI | |
NSApplication.shared.run { | |
VStack { | |
Text("Hello, World") | |
.padding() | |
.background(Capsule().fill(Color.blue)) |
I hereby claim:
- I am phucledien on github.
- I am phucld (https://keybase.io/phucld) on keybase.
- I have a public key ASBiatEcxVZQ9aCLuqHPeKcmWtPgFsgs6GG9kkSCD70I5Qo
To claim this, I am signing this object:
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
/// Every view interacting with a `SayHelloViewModel` instance can conform to this. | |
protocol SayHelloViewModelBindable { | |
var disposeBag: DisposeBag? { get } | |
func bind(to viewModel: SayHelloViewModel) | |
} | |
/// TableViewCells | |
final class TextFieldCell: UITableViewCell, SayHelloViewModelBindable { | |
@IBOutlet weak var nameTextField: UITextField! | |
var disposeBag: DisposeBag? |
All libraries have subtle rules that you have to follow for them to work well. Often these are implied and undocumented rules that you have to learn as you go. This is an attempt to document the rules of React renders. Ideally a type system could enforce it.
A number of methods in React are assumed to be "pure".
On classes that's the constructor, getDerivedStateFromProps, shouldComponentUpdate and render.