Skip to content

Instantly share code, notes, and snippets.

View diederikh's full-sized avatar

Diederik Hoogenboom diederikh

View GitHub Profile
- (NSString *) hostname
{
char baseHostName[256]; // Thanks, Gunnar Larisch
int success = gethostname(baseHostName, 255);
if (success != 0) return nil;
baseHostName[255] = '\0';
return [NSString stringWithFormat:@"%s", baseHostName];
}
class FontSizesDataSource: UITableViewDataSource {
private let fontSizeMultiplierDescriptions: [FontSizeMultiplier] = [.small, .normal, .large, .extraLarge]
var numberOfSections: Int {
return 1
}
func numberOfItemsInSection(index: Int) -> Int {
return fontSizeMultiplierDescriptions.count
@diederikh
diederikh / gist:9ad97c4cd05c42f46bf174246ef00365
Created December 5, 2016 10:55
preferredStatusBarStyle extension for nav controller
extension UINavigationController {
open override var preferredStatusBarStyle: UIStatusBarStyle {
return topViewController?.preferredStatusBarStyle ?? .default
}
}
import Foundation
import CommonCryptoKit
enum CryptoAlgorithm {
case MD5, SHA1, SHA224, SHA256, SHA384, SHA512
var HMACAlgorithm: CCHmacAlgorithm {
var result: Int = 0
switch self {
case .MD5: result = kCCHmacAlgMD5
class Dynamic<T> {
typealias Listener = T -> Void
var listener: Listener?
func bind(listener: Listener?) {
self.listener = listener
}
func bindAndFire(listener: Listener?) {
self.listener = listener
extension UIView {
func xscale() -> CGFloat {
let t = self.transform
return sqrt(t.a * t.a + t.c * t.c)
}
func yscale() -> CGFloat {
let t = self.transform
return sqrt(t.b * t.b + t.d * t.d);
}
let defaultOptions: [String: AnyObject] = [
"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints": true
]
NSUserDefaults.standardUserDefaults().registerDefaults(defaultOptions)
class AccessibilityBarButtonItem: UIBarButtonItem {
@IBInspectable override var accessibilityLabel: String? {
get { return super.accessibilityLabel }
set { super.accessibilityLabel = accessibilityLabel }
}
}
@diederikh
diederikh / ReplaceSegue.swift
Last active September 14, 2015 19:43
Replace child view controller segue
class ReplaceSegue: UIStoryboardSegue {
override func perform() {
let containerViewController = sourceViewController
if containerViewController.childViewControllers.count == 0 {
return;
}
let sourceVC = containerViewController.childViewControllers[0]
containerViewController.addChildViewController(destinationViewController)
@diederikh
diederikh / gist:a510b99981d5d1c2857f
Created January 5, 2015 10:00
dequeueUsingReuseID in Swift
import UIKit
class ExpenseListViewController : UITableViewController, UITableViewDataSource, UITableViewDelegate {
struct TableViewCellIdentifiers {
static let BasicCell = "BasicCell"
}
// MARK: - UITableViewDataSource