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
| // Change Youtube video playback speed | |
| 1. document.getElementsByClassName("video-stream html5-main-video")[0].playbackRate = 2.5 | |
| 2. document.querySelector('video').playbackRate = 2.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
| import Foundation | |
| @MainActor | |
| func test() async { | |
| print(0, Thread.isMainThread) | |
| Task { | |
| print(1, Thread.isMainThread) | |
| } | |
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 Test { | |
| func asyncGetImageFromClosure() async throws -> UIImage { | |
| try await withCheckedThrowingContinuation { continuation in | |
| getImageInClosure { result in | |
| switch result { | |
| case let .success(image): | |
| continuation.resume(returning: image) | |
| case let .failure(error): | |
| continuation.resume(throwing: error) |
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://swiftsenpai.com/swift/understanding-task-groups | |
| */ | |
| import UIKit | |
| enum ImageStyle: CaseIterable { | |
| case small | |
| case medium | |
| case large |
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
| /* | |
| Example based on API service: `https://api.quotable.io` | |
| */ | |
| import Foundation | |
| //MARK: Usage Example | |
| let provider: QuoteProvider = QuoteAPIProvider() | |
| Task { |
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://jllnmercier.medium.com/swift-propertywrapper-with-publisher-2e7132aab3e1 | |
| import Combine | |
| @propertyWrapper | |
| class MyPublished<T> { | |
| var wrappedValue: T { | |
| didSet { | |
| subject.send(wrappedValue) |
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
| /* | |
| Refs: | |
| - https://springframework.guru/gang-of-four-design-patterns/builder-pattern | |
| - https://refactoring.guru/design-patterns/builder/swift/example#example-1 | |
| */ | |
| import UIKit | |
| enum Shape { | |
| case circle(radius: Double) |
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
| class Node<T: Equatable> { | |
| let value: T | |
| var next: Node<T>? | |
| init(_ value: T, next: Node<T>? = nil) { | |
| self.value = value | |
| self.next = next | |
| } | |
| } |
NewerOlder