Skip to content

Instantly share code, notes, and snippets.

View Kievkao's full-sized avatar

Andrii Kravchenko Kievkao

View GitHub Profile
@Kievkao
Kievkao / Alamofire+NetworkRouter.swift
Created January 5, 2016 10:32
Alamofire network router snippet
import Alamofire
enum NetworkRouter: URLRequestConvertible {
static let baseURLString = "xxx"
case UserLogin(Int)
var URLRequest: NSMutableURLRequest {
@Kievkao
Kievkao / TransitioningDelegate.swift
Last active January 5, 2016 14:06
Custom transitioning snippets
class MyTransitionDelegate : NSObject, UIViewControllerTransitioningDelegate {
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return MyAnimatedTransitioning(isPresented: true)
}
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return MyAnimatedTransitioning(isPresented: false)
}
@Kievkao
Kievkao / BlurredTableView.swift
Created January 5, 2016 14:08
Blurred tableView background
func backgroundBlurSetup() {
// for clear background also need to set a modal segue to this controller into "OverCurrentContext"
self.view.backgroundColor = UIColor.clearColor()
let blurEffect = UIBlurEffect(style: .Light)
let effectView = UIVisualEffectView(effect: blurEffect)
effectView.frame = self.view.frame
self.tableView.backgroundView = effectView
}
@Kievkao
Kievkao / SwiftGCD.swift
Created January 23, 2016 14:54
Swiftier GCD (by Luo Jie)
protocol ExcutableQueue {
var queue: dispatch_queue_t { get }
}
extension ExcutableQueue {
func execute(closure: () -> Void) {
dispatch_async(queue, closure)
}
}
@Kievkao
Kievkao / dispatchAfter.swift
Last active May 10, 2016 13:55
Swift dispatch_after
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(UInt64(<#delayInSeconds#>) * NSEC_PER_SEC)), dispatch_get_main_queue()) {
<#code to be executed after a specified delay#>
}
@Kievkao
Kievkao / BuildVersion.swift
Created February 1, 2016 14:21
Get App version, build number
if let shortVersion = NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"] as? String, build = NSBundle.mainBundle().infoDictionary?["CFBundleVersion"] as? String {
}
@Kievkao
Kievkao / BuildVersion.swift
Created February 1, 2016 14:21
Get App version, build number
if let shortVersion = NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"] as? String, build = NSBundle.mainBundle().infoDictionary?["CFBundleVersion"] as? String {
}
@Kievkao
Kievkao / CustomBackButtonWithOffset.swift
Created February 3, 2016 11:17
Custom UINavigationBar back button with title offset adjustment
UINavigationBar.appearance().backIndicatorImage = image
UINavigationBar.appearance().backIndicatorTransitionMaskImage = image
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: 10, vertical: 0), forBarMetrics: .Default)
@Kievkao
Kievkao / SearchCollectionAppearance.swift
Last active February 4, 2016 14:31
UISearchController & UICollection/Table View
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.extendedLayoutIncludesOpaqueBars = true
self.edgesForExtendedLayout = .Top
}
@Kievkao
Kievkao / PinConstraints.swift
Created February 8, 2016 09:53
Pin view to it's superview's layoutGuides
func pinnedConstraints(view: UIView) -> [NSLayoutConstraint] {
let topConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.topLayoutGuide, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.bottomLayoutGuide, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0)
return [topConstraint, leftConstraint, bottomConstraint, rightConst