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
| // | |
| // VisionFaceTracker.swift | |
| // Test | |
| // | |
| // Created by Siarhei Yakushevich on 28.09.21. | |
| // | |
| import Foundation | |
| import Vision |
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
| // | |
| // CIFaceFilter.swift | |
| // | |
| import Foundation | |
| import CoreImage | |
| import CoreGraphics | |
| // MARK: - FaceFilterFeatures | |
| struct FaceFilterFeatures { |
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 str: String? | |
| let result0 = str.flatMap { Int($0) }.valueOrDefault(.min) | |
| var result1: Int = .min | |
| if let str = str { | |
| result1 = Int(str) ?? .min | |
| } | |
| // result1 can be changed here, but result0 can't. | |
| assert(result0 == result1) |
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 String { | |
| static let empty = "" // swift 5.5 allows static let constructs in extension | |
| #if DEBUG | |
| func check() { | |
| assert(Self.empty == "") | |
| } | |
| #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
| import Foundation | |
| extension Optional { | |
| var hasValue: Bool { | |
| if case .some = self { | |
| return true | |
| } | |
| return 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
| // MARK: - Atomic | |
| @propertyWrapper struct Atomic<T> { | |
| private let lock = UnfairLock() | |
| private var value: T | |
| var wrappedValue: T { | |
| get { | |
| lock.lock() | |
| defer { |
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
| // MARK: - UnfairLock | |
| final class UnfairLock { | |
| private let unfairLock: os_unfair_lock_t //UnsafeMutablePointer<os_unfair_lock> | |
| private let unfairValue: os_unfair_lock_s | |
| init() { | |
| unfairLock = .allocate(capacity: 1) | |
| unfairValue = .init() | |
| unfairLock.initialize(to: unfairValue) | |
| } |
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
| final class Test { | |
| private let queue: DispatchQueue | |
| private let queueKey : DispatchSpecificKey<Int> | |
| private let queueKeyValue: Int | |
| init() { | |
| let queueKey = DispatchSpecificKey<Int>() | |
| let queueKeyValue = Int(arc4random()) | |
| self.queueKey = queueKey |
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 UIView | |
| extension UILabel { | |
| func markAsMultiline() { | |
| numberOfLines = 0 | |
| lineBreakMode = .byWordWrapping | |
| } | |
| } |
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 Test1: MainThreadRunnerType { | |
| func displayMessage(_ text: String) { | |
| debugPrint(text) | |
| } | |
| func displayMessage(optText: String?) { | |
| guard let text = optText else { return } | |
| displayMessage(text) | |
| } | |
NewerOlder