Skip to content

Instantly share code, notes, and snippets.

public extension MoyaProvider {
public func request(_ target: Target,
callbackQueue: DispatchQueue? = nil,
progress: ProgressBlock? = nil) -> Promise<Moya.Response> {
return Promise { [weak self] fulfill, reject in
self?.request(
target,
callbackQueue: callbackQueue,
progress: progress,
completion: self?.completion(for: fulfill, reject: reject) ?? {_ in }
@aibobrov
aibobrov / Logging.swift
Created September 14, 2018 08:39
Simple logger for Swift
import Foundation
fileprivate extension String {
var sourceFileName: String {
let fileName = self.components(separatedBy: "/").last?.split(separator: ".").first ?? ""
return String(fileName)
}
}
public class Logger {
@aibobrov
aibobrov / KeyboardManager.swift
Last active October 5, 2018 22:56
Keyboard manager that helps to manage keyboard events
import UIKit
open class KeyboardManager: NSObject {
public enum KeyboardEvent {
case willShow
case didShow
case willHide
case didHide
case willChangeFrame
case didChangeFrame
@aibobrov
aibobrov / View.swift
Created September 17, 2018 13:57
IBDesignable subclass of UIView
import UIKit
@IBDesignable
public class View: UIView {
// MARK: - Layer stuff
@IBInspectable
public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
@aibobrov
aibobrov / Button.swift
Created September 17, 2018 13:58
IBDesignable subclass of UIButton
import UIKit
@IBDesignable
class Button: UIButton {
// MARK: - Layer stuff
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
@aibobrov
aibobrov / ImageView.swift
Created September 17, 2018 13:59
IBDesignable subclass of UIImageView
import UIKit
@IBDesignable
class ImageView: UIImageView {
// MARK: - Layer stuff
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
@aibobrov
aibobrov / CustomXibView.swift
Created September 17, 2018 14:05
Subclass of UIView for comfort creating custom views from Xib
import UIKit
/*
Usage:
1. Create new xib file.
2. Create new swift file containg class subclassed from CustomXibView.
3. In xib set recently created class name as File's owner.
*/
@aibobrov
aibobrov / SteppedSlider.swift
Created September 17, 2018 14:06
Simple SteppedSlider in swift. Subclass of UISlider
import UIKit
@IBDesignable
class SteppedSlider: UISlider {
@IBInspectable var stepSize: Int = 1
@IBInspectable var normalThumbImage: UIImage? {
get {
return thumbImage(for: .normal)
}
@aibobrov
aibobrov / PolygonMaskedView.swift
Created September 17, 2018 14:09
View masked by a rounded polygon
import UIKit
extension UIBezierPath {
/// Makes a bezier path which can be used for a rounded polygon
/// layer
///
/// - Parameters:
/// - rect: uiview rect bounds
/// - lineWidth: width border line
/// - sides: number of polygon's sides
@aibobrov
aibobrov / SelfSizedTableView.swift
Created September 17, 2018 14:09
Self sized UITableView
import UIKit
class SelfSizedTableView: UITableView {
lazy var heightConstraint: NSLayoutConstraint = {
let constraint = NSLayoutConstraint(item: self, attribute: .height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: bounds.height)
return constraint
}()
override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: frame, style: style)