Skip to content

Instantly share code, notes, and snippets.

View robnadin's full-sized avatar

Rob Nadin robnadin

View GitHub Profile
@robnadin
robnadin / AutoSizingCell.swift
Created December 24, 2014 08:58
Workaround for self-sizing table view cells on iOS 8
//
// AutoSizingCell.swift
//
//
// Created by Rob Nadin on 24/12/2014.
// Copyright (c) 2014 Rob Nadin. All rights reserved.
//
import UIKit
@robnadin
robnadin / AView.swift
Last active August 29, 2015 14:14
How to load a UIView subclass from a nib using designated initializers in Swift
//
// AView.swift
// LoadViewFromNib
//
// Created by Rob Nadin on 27/01/2015.
// Copyright (c) 2015 Rob Nadin. All rights reserved.
//
import UIKit
@robnadin
robnadin / CSStickyHeaderFlowLayout.m
Created February 12, 2015 20:08
Non-stretchable sticky header collection view flow layout
/*
* This file is part of the CSStickyHeaderFlowLayout package.
* (c) James Tang <j@jamztang.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "CSStickyHeaderFlowLayout.h"
#import "CSStickyHeaderFlowLayoutAttributes.h"
@robnadin
robnadin / DetailViewController.swift
Created February 16, 2015 00:47
Animated navigation bar tint color on push and interactive pop
//
// DetailViewController.swift
// TransitionCoordinator
//
// Created by Rob Nadin on 15/02/2015.
// Copyright (c) 2015 Rob Nadin. All rights reserved.
//
import UIKit
@robnadin
robnadin / !Fetchable.swift
Last active August 29, 2015 14:26
An extendable protocol for NSManagedObject subclasses for simple data fetching
//
// Fetchable.swift
// CoreDataGenerics
//
// Created by Rob Nadin on 29/07/2015.
// Copyright © 2015 Rob Nadin. All rights reserved.
//
import CoreData
@robnadin
robnadin / DecimalNumberHandlerExtensions.swift
Created July 31, 2015 08:45
Extensions to the NSDecimalNumberHandler class for more Swift-like decimal number operations when using a custom decimal number behaviour
extension NSDecimalNumberHandler {
public func calculate(closure: () -> NSDecimalNumber) -> NSDecimalNumber {
let defaultBehavior = NSDecimalNumber.defaultBehavior()
NSDecimalNumber.setDefaultBehavior(self)
let result = closure()
NSDecimalNumber.setDefaultBehavior(defaultBehavior)
return result
}
}
@robnadin
robnadin / debug_ats_allow_host.sh
Created September 3, 2015 10:57
Xcode 7 run script phase to exclude a specific domain from App Transport Security via user-defined build settings
if [ "$ALLOW_INSECURE_HTTP_LOADS" = "YES" ]; then
PLIST_BUDDY="/usr/libexec/PlistBuddy"
cd "${TARGET_BUILD_DIR}"
DOMAIN_PATH=":NSAppTransportSecurity:NSExceptionDomains:${INSECURE_SERVER_HOST}"
$PLIST_BUDDY -c "Delete ${DOMAIN_PATH}" "${INFOPLIST_PATH}"
$PLIST_BUDDY -c "Add ${DOMAIN_PATH} dict" "${INFOPLIST_PATH}"
$PLIST_BUDDY -c "Add ${DOMAIN_PATH}:NSExceptionAllowsInsecureHTTPLoads bool true" "${INFOPLIST_PATH}"
fi

NSDecimalNumber Integer Fix

So given the decimal 109268.27107118553088 the result is:

32-bit architecture

integer: 0
int: 109268
uint: 109268
unsigned integer: 0
@robnadin
robnadin / Array+Operators.swift
Last active January 8, 2016 15:52
Custom Swift operators to handle array contents
//
// Array+Operators.swift
//
//
// Created by Rob Nadin on 08/01/2016.
// Copyright © 2016 Rob Nadin. All rights reserved.
//
import Foundation
@robnadin
robnadin / Brightness.swift
Last active January 22, 2016 11:36
Set brightness based on hour
/* Brightness.swift -- Set brightness based on hour
This file is part of brightness.
Brightness is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Brightness is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of