Skip to content

Instantly share code, notes, and snippets.

Pavan Kataria pavankataria

Block or report user

Report or block pavankataria

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pavankataria
pavankataria / SortButton.swift
Created Nov 29, 2017
A UIButton subclass that renders a sort button.
View SortButton.swift
fileprivate extension UIControlState {
static let unspecified = UIControlState(rawValue: 1 << 16)
static let ascending = UIControlState(rawValue: 1 << 17)
static let descending = UIControlState(rawValue: 1 << 18)
}
class SortButton: UIButton {
private var customState: UIControlState = .unspecified {
didSet {
setNeedsLayout()
@pavankataria
pavankataria / GenericTableViewCell.plagrounds
Created Oct 6, 2017
Injecting View into Generic TableViewCell
View GenericTableViewCell.plagrounds
import Foundation
import UIKit
public protocol CellRepresentable {
static func registerCell(tableView: UITableView)
func dequeueCell(tableView: UITableView, indexPath: IndexPath) -> UITableViewCell
func cellSelected(_ indexPath: IndexPath)
}
//MARK: - Default Implementation
@pavankataria
pavankataria / HasDisposeBag.swift
Created Sep 29, 2017
A protocol for automatically adding a dispose bag to any object that requires it. Uses associated objects.
View HasDisposeBag.swift
//
// HasDisposeBag.swift
//
// Created by Pavan Kataria 26/09/2017
// Copyright © 2017 Pavan Kataria. All rights reserved.
protocol HasDisposeBag {
var disposeBag: DisposeBag { get }
}
private struct AssociatedKeys {
View SwiftSnippet.md
    class MyAppCantFunctionUnlessBothPropertiesAreBloodyPresent {
        var cloudId: String?
        var apnsToken: String?
        func pleaseJustSendThisShitToMyServerSoICanBeDoneWith() {
          guard let cloudId = self.cloudId, apnsToken = self.apnsToken else {
              print(“Sighs, nope not ready yet, we’re all probably waiting for that blaady apns token again")
              return
          }
          print(“what took you two so long? Let’s make that request to igors server now")
@pavankataria
pavankataria / Duplication
Created Jan 7, 2016
there's some serious duplication here with this default parameterised methods with the completion handler
View Duplication
class ApiManager {
class func GET(
URLString: URLStringConvertible,
parameters: [String : AnyObject]? = nil,
encoding: ParameterEncoding? = .URL,
headers: [String : String]? = nil,
completionHandler: CompletionHandlerType
){
alamofireManager().request(.GET, URLString, parameters: parameters, encoding: encoding!, headers: headers)
.validate()
@pavankataria
pavankataria / PKNavigationController
Last active Dec 29, 2015
Adds a navigation item on all navigation controllers that inherit this class.
View PKNavigationController
//
// PKNavigationController.swift
//
// Created by Pavan Kataria on 29/12/2015.
// Copyright © 2015 Pavan Kataria. All rights reserved.
//
import UIKit
class PKNavigationController: UINavigationController {
You can’t perform that action at this time.