Skip to content

Instantly share code, notes, and snippets.

View VadimYakovliev's full-sized avatar
👻
BO0o...

YVV VadimYakovliev

👻
BO0o...
  • Kyiv, Ukraine
  • 14:07 (UTC +03:00)
View GitHub Profile
@VadimYakovliev
VadimYakovliev / InteractiveTransitionTableViewDeselection.m
Created January 9, 2018 18:15 — forked from smileyborg/InteractiveTransitionCollectionViewDeselection.m
Animate table view deselection alongside interactive transition on iOS 11
/*
In iOS 11, interactive view controller transitions no longer scrub by setting the layer speed to zero
and changing the timeOffset. As a result of this change, implicit animations that occur in places like
-viewWillAppear: (called during an interactive transition) no longer end up “caught in” the animation.
To get the same behavior for table view row deselection as before, you can either use UITableViewController
which implements this for you, or you can implement it manually by deselecting the row in an alongside
animation for the transition (set up in -viewWillAppear: using the transition coordinator).
Here is an example implementation which correctly handles some of the more subtle corner cases:
// https://github.com/avito-tech
private class ObserverBox<T>: Hashable {
typealias Observer = T
private(set) weak var disposable: AnyObject?
private let objectIdentifier: ObjectIdentifier
var observers = [Observer]()
let hashValue: Int
@VadimYakovliev
VadimYakovliev / Result.swift
Last active May 23, 2018 09:38 — forked from maxsokolov/Result.swift
Result with Erroe handler
enum Result<T, E> {
case value(T)
case error(E)
var value: T? {
switch self {
case .value(let value):
return value
case .error:
@VadimYakovliev
VadimYakovliev / Timer.swift
Last active June 2, 2018 20:42 — forked from maxsokolov/Timer.swift
gcd based timer using swift
//*****************************************************************
// MARK: - GCD based utility
//*****************************************************************
private let timerQueue = DispatchQueue(label: "com.timer.queue",
attributes: [])
final class Timer : NSObject {
private var dispatchTimer: DispatchSourceTimer?
@VadimYakovliev
VadimYakovliev / sketch-never-ending.md
Created July 8, 2018 18:52 — forked from Bhavdip/sketch-never-ending.md
Modify Sketch to never ending trial

###Sketch trial non stop

Open hosts files:

$ open /private/etc/hosts

Edit the file adding:

127.0.0.1 backend.bohemiancoding.com

127.0.0.1 bohemiancoding.sketch.analytics.s3-website-us-east-1.amazonaws.com

@VadimYakovliev
VadimYakovliev / UIAlertController+TextField.swift
Created September 2, 2018 08:25 — forked from ole/UIAlertController+TextField.swift
A UIAlertController with a text field and the ability to perform validation on the text the user has entered while the alert is on screen. The OK button is only enabled when the entered text passes validation. More info: https://oleb.net/2018/uialertcontroller-textfield/
import UIKit
/// A validation rule for text input.
public enum TextValidationRule {
/// Any input is valid, including an empty string.
case noRestriction
/// The input must not be empty.
case nonEmpty
/// The enitre input must match a regular expression. A matching substring is not enough.
case regularExpression(NSRegularExpression)
@VadimYakovliev
VadimYakovliev / TableState.swift
Last active October 1, 2018 06:53 — forked from nickoneill/TableState.swift
Add async state tracking to UITableView data sources
/*
Here’s a more general implementation of TableState that works for all types, provided your type conforms to the simple TableValuable protocol.
*/
protocol TableValuable {
associatedtype TableItem
static func loadingValue() -> TableItem
static func failedValue() -> TableItem
func value() -> TableItem
}
//:
//: UIView Animation Syntax Sugar
//:
//: Created by Andyy Hope on 18/08/2016.
//: Twitter: @andyyhope
//: Medium: Andyy Hope, https://medium.com/@AndyyHope
import UIKit
extension UIView {

High Order Functions in iOS Swift

Written by Sheldon, please find me with #iOSBySheldon in Github, Youtube, Facebook, etc.

It is exaggerating to say we don't need to use for loop or while loop any more but we can take advantage of the Swift language built in functions to do loops. If I give you a question now. Q: Assuming we have an optional nested array, please calculate the production of the values that are less than 5. let numbers: [[Int]?] = [[1, 3], nil, [2], [5, 10], nil, [4]], what is your best approach to do it?

And you know the solution that I am talking about is following Swift functions:

  1. Map
  2. FlatMap / CompactMap
{% for type in types.based.JSONAutoRepresentable| %}
// sourcery:inline:auto:{{ type.name }}.JSONAutoRepresentable
init(_ json: JSON) {
{% for variable in type.storedVariables where variable|!annotated:"skip" %}
{% elif variable.type.based.JSONAutoRepresentable %}
{{ variable.name }} = {{ variable.unwrappedTypeName }}(json["{{ variable.name|camelToSnakeCase }}"])
{% elif variable.isArray %}
{{ variable.name }} = json["{{ variable.name|camelToSnakeCase }}"].arrayValue.map({{ variable.typeName.array.elementTypeName.unwrappedTypeName }}.init)
{% elif variable.type.kind == "enum" %}
{{ variable.name }} = {{ variable.unwrappedTypeName }}(rawValue: json["{{ variable.name|camelToSnakeCase }}"].stringValue) ?? {{ variable.defaultValue }}