This file contains hidden or 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 | |
/// `PartialForEach` is used to show a partial number of items, and a view builder to toggle the expansion. | |
public struct PartialForEach<Data: RandomAccessCollection, ID: Hashable, ItemView: View, ExpandView: View> { | |
public enum ExpandPlacement { | |
case first, last | |
} | |
/// This type defines a lazy map from `Data.indices` to `(index, (value, id))` tuple. | |
/// The `index` is required for bindable `ForEach` initializer. |
This file contains hidden or 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
public struct TTDrawerModifier<DrawerContent: View, OverlayContent: View, Detent: TTDrawerDetent> { | |
struct AnimationValue: Equatable { | |
let isDragging: Bool | |
let drawerState: TTDrawerState<Detent> | |
init(view: TTDrawerModifier<DrawerContent, OverlayContent, Detent>) { | |
self.isDragging = view.dragHeight != nil | |
self.drawerState = view.state | |
} | |
} |
This file contains hidden or 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 | |
struct SomeView: View, Resizable { | |
var updateSize: () -> Void? | |
var body: some View { | |
// Option 1: call the closure in the body. | |
let _ = updateSize?() | |
Text("Hello World") | |
// Option 2: call the closure using a SizeReader helper below. |
This file contains hidden or 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
var body: some View { | |
ParticlesEmitter { | |
Particle(.circle(4)) | |
.color(.red) | |
.velocity(25) | |
.scale(0.10) | |
.alphaSpeed(-0.3) | |
.spinRange(1) | |
.lifetime(5) |
This file contains hidden or 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
var foo: String? | |
var bar: String? = "bar" | |
print(foo) // nil | |
print(foo.get(orSet: "foo")) // foo | |
print(foo) // Optional("foo") | |
print(bar) // Optional("bar") | |
print(bar.get(orSet: "test")) // bar | |
print(bar) // Optional("bar") |
This file contains hidden or 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
let value1: Int? = 1 | |
let value2: Int? = 2 | |
let nilValue: Int? = nil | |
value1 <? value2 // true | |
value1 <? nilValue // false | |
value2 != nilValue // true | |
value2 !=? nilValue // false |
This file contains hidden or 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
// US locale: | |
// Oct 14, 2020, 7:50 PM | |
Date().format(with: [.monthShort, .dayOfMonth, .yearFull, .hour, .minute], locale: Locale(identifier: "en_US"))! | |
// French locale: | |
// 14 Oct 2020 à 19:50 | |
Date().format(with: [.monthShort, .dayOfMonth, .yearFull, .hour, .minute], locale: Locale(identifier: "fr"))! |