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 / 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 / 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,
// 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 {
protocol TitlePresentable {
var titleLabel: UILabel! { get set }
func setTitle(title: String?)
}
extension TitlePresentable {
func setTitle(title: String?) {
titleLabel.text = title
}
}
protocol BytesCountPresentable {
var bytesCountLabel: UILabel! { get set }
func setBytesCount(bytesCount: Int64?)
}
extension BytesCountPresentable {
func setBytesCount(bytesCount: Int64?) {
bytesCountLabel.text = bytesCountString(bytesCount)
}
private func bytesCountString(bytesCount: Int64?) -> String {
class BytesCountTitleTableViewCell: UITableViewCell, TitlePresentable, BytesCountPresentable {
@IBOutlet var titleLabel: UILabel!
@IBOutlet var bytesCountLabel: UILabel!
}