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
| /* | |
| We are removing a product before listing all products so we don't expect to print 3 items. | |
| Since the queue will be executed concurrently, there's no guarantee which task will execute first. | |
| */ | |
| func withoutBarrier() { | |
| // We will sometimes see a list of 3 items instead of 2 | |
| for i in 1...1000 { | |
| var resources = ["Product A", "Product B", "Product C"] | |
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
| imageView.layer.cornerRadius = imageView.bounds.width/2 | |
| imageContainerView.layer.masksToBounds = false | |
| imageContainerView.layer.cornerRadius = imageContainerView.bounds.width/2 | |
| imageContainerView.layer.shadowColor = UIColor.black.cgColor | |
| imageContainerView.layer.shadowOpacity = 0.3 | |
| imageContainerView.layer.shadowRadius = 2 | |
| imageContainerView.layer.shadowOffset = .zero |
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 UIKit | |
| class SegmentedCircleView: UIView { | |
| private var piMultipliers: [(Double,Double)] { | |
| switch enablers.count { | |
| case 1: | |
| return [(3/2, 4)] | |
| case 2: | |
| return [(3/2, 1/2), (1/2, 3/2)] | |
| default: |
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 Foundation | |
| class Dynamic<T> { | |
| typealias Listener = (T) -> Void | |
| private var listener: Listener? | |
| private var thread: RunLoop = .current | |
| var value: T { | |
| didSet { |
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
| //Ref: https://medium.com/@johnsundell/writing-unit-tests-in-swift-playgrounds-9f5b6cdeb5f7 | |
| import XCTest | |
| class ExampleTests: XCTestCase { | |
| func textExample1() { | |
| XCTAssertEqual(2 * 2, 4) | |
| } | |
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
| /* | |
| Ref: | |
| - https://stackoverflow.com/q/44195986/2857130 | |
| - https://useyourloaf.com/blog/variable-height-table-view-header/ | |
| */ | |
| override func viewDidLayoutSubviews() { | |
| super.viewDidLayoutSubviews() | |
| if let headerView = tableView.tableHeaderView { |
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
| extension URLComponents { | |
| var fragments: [String:String]? { | |
| return fragment? | |
| .split(separator: "&") | |
| .reduce(into: [:]) { partialResult, fragment in | |
| let parts = fragment.split(separator: "=") | |
| let key = String(parts[0]) | |
| let value = String(parts[1]) | |
| partialResult?[key] = 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
| protocol SomeProvider { | |
| func getSomething(completion: @escaping (Result<Any,Error>)->Void) | |
| } | |
| extension SomeProvider { | |
| func fallback(to provider: SomeProvider) -> SomeProvider { | |
| SomeFallbackProvider(initial: self, fallback: provider) | |
| } | |
| } |
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
| // Prevent `print` in Release mode | |
| func print(_ args: Any..., separator: String = " ", terminator: String = "\n") { | |
| #if DEBUG | |
| let output = args.map(String.init(describing:)).joined(separator: separator) | |
| print(output, terminator: terminator) | |
| #endif | |
| } |
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
| //Ref: https://stackoverflow.com/q/56561064/2857130 | |
| struct ItemListView: View { | |
| var body: some View { | |
| VStack { | |
| List(0..<3) { section in | |
| ItemOption(section: section) | |
| .padding() | |
| } | |
| } |