This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
struct Distance { | |
let value: Double | |
} | |
struct Time { | |
let value: Double | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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:)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | |
segue.destinationViewController.title = customTitle() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController, UITableViewDataSource { | |
@IBOutlet var tableView: UITableView! | |
var dataSource: [DataItem] | |
// MARK: UITableViewDataSource | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return dataSource.count | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: UITableViewDelegate | |
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
let cell = tableView.cellForRowAtIndexPath(indexPath) | |
if shouldPerformSegue(cell) { | |
self.performSegueWithIdentifier("CellDetailSegue", sender: cell) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
OlderNewer