Skip to content

Instantly share code, notes, and snippets.

View bizz84's full-sized avatar

Andrea Bizzotto bizz84

View GitHub Profile
@bizz84
bizz84 / DistanceTimeVelocity.swift
Last active August 29, 2015 14:17
SwiftStrongTyping-DistanceTimeVelocity
// Playground - noun: a place where people can play
struct Distance {
let value: Double
}
struct Time {
let value: Double
}
@bizz84
bizz84 / UIViewAutoLayoutAnchors.swift
Last active April 10, 2019 14:51
UIView extension for programmatic Auto Layout
import UIKit
extension UIView {
func anchorAllEdgesToSuperview() {
self.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 9.0, *) {
addSuperviewConstraint(topAnchor.constraintEqualToAnchor(superview?.topAnchor))
addSuperviewConstraint(leftAnchor.constraintEqualToAnchor(superview?.leftAnchor))
addSuperviewConstraint(bottomAnchor.constraintEqualToAnchor(superview?.bottomAnchor))
@bizz84
bizz84 / UIViewController+Tracking
Last active December 10, 2015 14:56
Example of method swizzling on UIViewController
#import <objc/runtime.h>
@implementation UIViewController(Tracking)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self swizzleOriginalSelector:@selector(performSegueWithIdentifier:sender:)
swizzledSelector:@selector(xxx_performSegueWithIdentifier:sender:)];
@bizz84
bizz84 / MVPhotoPicker
Created February 12, 2016 08:38
Simple Block-based wrapper around UIImagePickerController
import UIKit
class MVPhotoPicker: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
// Class to hold strong reference to the currently presented photo picker controller
private class PhotoPickerController {
var currentPicker: MVPhotoPicker?
static let sharedInstance = PhotoPickerController()
@bizz84
bizz84 / count_ios.sh
Created May 28, 2016 07:38
Script to count lines of code (.swift and .h and .m) for XCode projects
#!/bin/bash
# Script to count lines of code (.swift and .h and .m) for XCode projects
find . "(" -name "*.swift" -or -name "*.m" -or -name "*.h" ")" -print0 | xargs -0 wc -l | sort -n
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
segue.destinationViewController.title = customTitle()
}
class DestinationViewController: UIViewController {
var viewModel: ViewModel!
@IBOutlet var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// viewModel should be set by prepareForSegue. It it's not,
class ViewController: UIViewController, UITableViewDataSource {
@IBOutlet var tableView: UITableView!
var dataSource: [DataItem]
// MARK: UITableViewDataSource
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count
}
// MARK: UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
if shouldPerformSegue(cell) {
self.performSegueWithIdentifier("CellDetailSegue", sender: cell)
}
}
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
@IBAction var sourceButton: UIButton!
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "SlideshowPopoverSegue" {
let contentViewController = segue.destinationViewController
contentViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
if let popover = contentViewController.popoverPresentationController {