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
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate | |
{ | |
if (scrollView.scrollDirectionX == ScrollDirectionRight) { | |
//Do something with your views etc | |
} | |
if (scrollView.scrollDirectionY == ScrollDirectionUp) { | |
//Do something with your views etc | |
} | |
} |
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 RxSwift | |
import Alamofire | |
extension Single { | |
static func make<T>(from resultFn: @escaping (@escaping (Result<T>) -> Void) -> Void) -> Single<T> { | |
return Single<T>.create { sub in | |
resultFn { result in | |
switch result { | |
case .success(let value): | |
sub(SingleEvent.success(value)) |
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 Foundation | |
enum Nullable<Value: Codable>: Codable { | |
case some(_ value: Value) | |
case null | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
if container.decodeNil() { | |
self = .null |
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 Vapor | |
import StackdriverLogging | |
extension LoggingSystem { | |
/// Prepare the `StackdriverLogHandlerFactory` and bootstrap the `LoggingSystem` to use `StackdriverLogHandler`s. | |
/// | |
/// - Returns: A `StackdriverLoggerLifecycleHandler` that must be passed to the `Vapor.Application` `lifecyle` service | |
/// for proper shutdown of the NIO dependencies used by the logger when the `Application` shuts down. | |
public static func bootstrapStackdriverLogging(for environment: inout Environment, | |
with configuration: StackdriverLoggingConfiguration) throws -> StackdriverLoggerLifecycleHandler { |
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 NIO | |
import Logging | |
extension EventLoopFuture { | |
func whenFailureLog( | |
level: Logger.Level = .error, | |
_ message: @escaping @autoclosure () -> Logger.Message, | |
using logger: Logger, | |
errorDescriptionMetadataKey: String = "reason", | |
metadata: @escaping @autoclosure () -> Logger.Metadata? = nil, |
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
/// Raw representable `Codable` property wrapper used to instantiate to a `RawRepresentable` type if the `rawValue`decoded is supported | |
/// by the generic `RawRepresentableValue` type. This can be useful when you want to decode a set of constant values | |
/// specified inside `RawRepresentable` enum yet default to the `rawValue` if the decoded `rawValue` is unsupported. | |
/// | |
/// For example, using this property wrapper you could decode an enum specifying a list of error code such as: | |
/// | |
/// enum ErrorCode: String, Codable { | |
/// case notFound, unauthorized, badRequest | |
/// } | |
/// |
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 class Dispatch.DispatchQueue | |
import NIO | |
public extension DispatchQueue { | |
/// `DispatchQueue.async` but returning a NIO future wrapping the closure return. | |
func async<Value>(on eventLoop: EventLoop, use closure: @escaping () throws -> Value) -> EventLoopFuture<Value> { | |
let promise = eventLoop.makePromise(of: Value.self) | |
async { | |
do { | |
promise.succeed(try closure()) |
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 Nullable<T>: Codable where T: Codable { | |
case some(_ value: T) | |
case null | |
case undefined | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
if container.decodeNil() { | |
self = .null | |
} else { |
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 Vapor | |
import RedisKit | |
struct MySession { | |
let token: RedisKey | |
let email: String | |
let userId: Int64 | |
let isAdmin: Bool | |
let ipAddress: 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
public struct ResultCodable<CodableType>: Codable where CodableType: Codable { | |
private enum EncodingError: Swift.Error, CustomStringConvertible { | |
case encodedErrorResult(encodingError: Swift.Error) | |
var description: String { | |
switch self { | |
case .encodedErrorResult(let encodingError): | |
return "Cannot encode `Result.failure` which resulted from decoding error: '\(encodingError)'" | |
} |
OlderNewer