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
/* | |
* | |
* This class provides a UIViewController extension which adds a tag property to all UIViewController subclasses. | |
* | |
*/ | |
import Foundation | |
private var tagAssociationKey: UInt8 = 0 |
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
func animateStatusBarHidden(hidden: Bool) { | |
let key = NSString(data: NSData(bytes: [0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72] as [CUnsignedChar], length: 9), encoding: NSASCIIStringEncoding) | |
let object = UIApplication.sharedApplication() | |
var statusBar: UIView? | |
if let mKey = key as? String { | |
if object.respondsToSelector(NSSelectorFromString(mKey)) { | |
statusBar = object.valueForKey(mKey) as? UIView | |
} | |
} | |
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
extension CALayer { | |
func borderUIColor() -> UIColor? { | |
return borderColor != nil ? UIColor(CGColor: borderColor!) : nil | |
} | |
func setBorderUIColor(color: UIColor) { | |
borderColor = color.CGColor | |
} | |
} |
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
// Initialize a color from hex string with format #RRGGBB | |
extension UIColor { | |
convenience init(hex: String, alpha: CGFloat = 1) { | |
assert(hex[hex.startIndex] == "#", "Expected hex string of format #RRGGBB") | |
let scanner = NSScanner(string: hex) | |
scanner.scanLocation = 1 // skip # | |
var rgb: UInt32 = 0 | |
scanner.scanHexInt(&rgb) |
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
let shadowPath = UIBezierPath(rect: self.myView.layer.bounds) | |
self.myView.layer.masksToBounds = false | |
self.myView.layer.shadowColor = UIColor.blackColor().CGColor | |
self.myView.layer.shadowOffset = CGSizeMake(0.0, -2.0) | |
self.myView.layer.shadowOpacity = 0.3 | |
self.myView.layer.shadowRadius = 1.0 | |
self.myView.layer.shadowPath = shadowPath.CGPath |
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 | |
/** | |
UIView subclass that is transparent to all touch events besides those on eligible child views. | |
*/ | |
class TKPassThroughView: UIView { | |
// MARK - Touch Handling | |
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
public class MyCustomObject: Equatable {} | |
// MARK: Equatable | |
/** | |
Evaluate equality as an identity check on an ObjectIdentifier constructed with an instance of our type. This is a public function in the global scope. | |
*/ | |
public func ==(lhs: MyCustomObject, rhs: MyCustomObject) -> Bool { | |
return ObjectIdentifier(lhs) == ObjectIdentifier(rhs) | |
} |
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
public someFunction() { | |
({ self.someStringVariable = "Some value" })() | |
} |
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
/** | |
Function that locks an object while it is being acted upon in the closure parameter. | |
Rethrows allows the function to throw an error for throwing closures or not for non-throwing closures (do not need `try` for non-throwing closures). | |
parameter lock: Object to be sync'd | |
parameter closure: Code of critical section | |
*/ | |
public func synchronized<T>(lock: AnyObject, @noescape closure: () throws -> T) rethrows -> T { | |
objc_sync_enter(lock) | |
defer { | |
objc_sync_exit(lock) |
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
// Perform selector | |
self.performSelector(#selector(MyViewController.myFunction(_:)), withObject: myObject, afterDelay: 1.0) | |
// Cancel perform requests | |
self.classForCoder.cancelPreviousPerformRequestsWithTarget(self, selector: #selector(MyViewController.myFunction(_:)), object: myObject) | |
// Note: - | |
// myObject can be nil |
OlderNewer