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
struct EquatablePack<each V: Equatable>: Equatable { | |
let value: (repeat each V) | |
init(_ value: repeat each V) { | |
self.value = (repeat each value) | |
} | |
static func == (lhs: Self, rhs: Self) -> Bool { | |
func throwIfNotEqual<T: Equatable>(_ lhs: T, _ rhs: T) throws { | |
guard lhs == rhs else { throw CancellationError() } |
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 | |
import UIKit | |
struct PageView<Page: View, T: Identifiable>: UIViewControllerRepresentable { | |
private class ModelViewController: UIHostingController<Page?> { | |
var id: T.ID? | |
init(id: T.ID?, rootView: Page?) { | |
self.id = id | |
super.init(rootView: rootView) |
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
struct GeometryReaderApproach: View { | |
private let values: [Double] = [152, 355, 475, 78, 173, 295] | |
private let maxValue: Double | |
init() { maxValue = values.max() ?? 0 } | |
var body: some View { | |
VStack { | |
let data = Array(zip(values.indices, values)) | |
// Why not use .enumerated? Well, in general it's is not necessarily the index of the paired value. |
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 | |
// Use Case: collect actions to perform menu commands | |
// | |
// Issue: Storing DetailsView context ( "isTakingSnapshot = true" ) leads to a memory leak | |
// All view associated memory storage doesn't get deallocated even though a view itself no longer exist | |
// Solution: move stored context to ViewModel and capture it as a weak reference | |
// MARK: - App |
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
/* | |
Collection view with UICollectionViewCompositionalLayout | |
resets section's content offset on vertical scroll | |
if visibleItemsInvalidationHandler is set. | |
Even if it's empty | |
*/ | |
import UIKit |