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
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
// 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 |
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 override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { | |
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) | |
// Before rotation (willTransitionToInterfaceOrientation) | |
// ... Do stuff that should happen before rotation ... // | |
coordinator.animateAlongsideTransition({ (context) in | |
// During rotation | |
// ... Do stuff that should happen during rotation ... // | |
}, | |
completion: { (context) in | |
// After rotation (didTransitionToInterfaceOrientation) |
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
/** | |
Batch request an array of images for background download task. This method fires completion block when ALL images are downloaded and returns an array of UIImage objects. | |
- Parameter imageURLs: Array of strings representing location of images as URL's | |
- Parameter completion: Block that provides a dictionary of downloaded images as argument. The dictionary contains images at the index they were passed in the original array and NSNull objects for images that failed to download. | |
- Parameter imageScale: Scale to interpret image data for UIImage. A scale of 1.0 will keep full size of image. Default (imageScale = nil) is scale factor of UIScreen resolution. | |
*/ | |
@objc | |
static func batchImageDownloadWithImageUrlArray(imageURLs: [String], imageScale: NSNumber?, completion: ((images: [Int : AnyObject]) -> Void)?) { | |
var imageDict = [Int : AnyObject]() // This should be UIImage? but Objective-C can't have nil in dictionaries | |
let manager = AFHTTPSessionManager() |
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
// 1.) Swift selectors must have @objc if they are not exposed to objective-c (i.e. they are private to a swift class) | |
// 2.) Make a failable initializer by adding an optional (?) after initializer (init?()) | |
// 3.) To cast in a for in loop use "case". Use "where" to unwrap optionals or check a condition. | |
for case let button as AClass in view.subviews { | |
} | |
for view in childViews where view is UIButton { | |
} | |
for case let view as MyCustomView in self.view.subviews { | |
view.removeFromSuperview | |
} |
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 | |
# Auto Increment Version Script | |
buildPlist=$INFOPLIST_FILE | |
echo $buildPlist | |
CFSVString=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$buildPlist") | |
CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist") | |
BUILD_NR=${CFBundleVersion##*.} | |
BUILD_NR=$(($BUILD_NR + 1)) | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NR" "$buildPlist" |
OlderNewer