This file contains 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 Combine | |
import Moya | |
extension Publishers { | |
struct MoyaRequest<Target: TargetType, Model: Decodable>: Publisher { | |
typealias Output = Model | |
typealias Failure = Error | |
private let provider: MoyaProvider<Target> | |
private let target: Target |
This file contains 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 Combine | |
import Moya | |
extension Publishers { | |
struct MoyaEmptyRequest<Target: TargetType>: Publisher { | |
typealias Output = Void | |
typealias Failure = Error | |
private let provider: MoyaProvider<Target> | |
private let target: Target |
This file contains 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
enum CodableTool { | |
@propertyWrapper | |
struct Nullable<T: Codable>: Codable { | |
var wrappedValue: T? | |
init(from decoder: Decoder) throws { | |
let container: SingleValueDecodingContainer = try decoder.singleValueContainer() | |
wrappedValue = try? container.decode(T.self) | |
} | |
This file contains 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 NSAttributedString { | |
func calcHeight(for width: CGFloat) -> CGFloat { | |
guard self.string.count > 0 else { return 0 } | |
let maxHeight: CGFloat = 10000 | |
let path: CGPath = CGPath(rect: .init(x: 0, y: 0, width: width, height: maxHeight), transform: nil) | |
let frame: CTFrame = ctFrame(for: path) | |
// swiftlint:disable force_cast | |
let lines: [CTLine] = CTFrameGetLines(frame) as! [CTLine] | |
// swiftlint:enadble force_cast |
This file contains 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 Combine | |
extension Publisher { | |
func transformToResult() -> Publishers.TransformToResult<Self> { | |
.init(upstream: self) | |
} | |
} | |
extension Publishers { | |
struct TransformToResult<Upstream: Publisher>: Publisher { |
This file contains 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 json = | |
""" | |
{ | |
"2021-06-20-Sun": { | |
"test": 0 | |
}, | |
"2021-06-21-Mon": { | |
"test": 0 | |
}, | |
"2021-06-22-Tue": { |
This file contains 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 Combine | |
extension Publisher { | |
func asError<ErrorType: Error>(type: ErrorType.Type, _ transform: @escaping (Self.Failure) -> ErrorType) -> Publishers.AsError<Self, ErrorType> { | |
return .init(upstream: self, type: type.self, transform) | |
} | |
} |
This file contains 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 TestInstance { | |
enum TestType { | |
case abcd | |
} | |
private let queue: DispatchQueue = DispatchQueue(label: "TestQueue") | |
private var showTypes: [TestType] = [] | |
func test01(with type: TestType) { | |
// [TestInstance.TestType].Index |
This file contains 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
enum UDTool { | |
fileprivate | |
enum Key: String { | |
case sample | |
} | |
@UDGeneric<String>(.sample, "") static var sample: String | |
} |
This file contains 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
enum ConvertDecimalError: Error { | |
case InvalidateValue | |
} | |
func converHexStringToDecimal(_ hex: String) throws -> Decimal { | |
if !hex.hasPrefix("0x") { | |
throw ConvertDecimalError.InvalidateValue | |
} | |
let strideCount: Int = 10 | |
let hexValue = hex.suffix(hex.count-2) |
NewerOlder