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 NSDate { | |
convenience init(ISO8601:String) { | |
let dateStringFormatter = NSDateFormatter() | |
dateStringFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" | |
dateStringFormatter.locale = NSLocale.systemLocale() | |
let d = dateStringFormatter.dateFromString(ISO8601) | |
self.init(timeInterval:0, sinceDate:d!) | |
} | |
class func getLastDayOfMonthFrom(month:Int,year:Int) -> NSDate { |
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 UIColor { | |
class func fromHexString(hex:String) -> UIColor { | |
let hex = hex.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet) | |
var int = UInt32() | |
NSScanner(string: hex).scanHexInt(&int) | |
let a, r, g, b: UInt32 | |
switch hex.characters.count { | |
case 3: // RGB (12-bit) | |
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17) | |
case 6: // RGB (24-bit) |
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 String { | |
func isEmail() -> Bool { | |
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}" | |
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx) | |
return emailTest.evaluateWithObject(self) | |
} | |
func convertStringToDictionary() -> [String:AnyObject]? { | |
if let data = self.dataUsingEncoding(NSUTF8StringEncoding) { | |
do { |
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
TAGS="TODO:|FIXME:" | |
echo "searching ${SRCROOT} for ${TAGS}" | |
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" |
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 UIView { | |
func roundCorners(corners:UIRectCorner, radius:CGFloat) { | |
let bounds = self.bounds; | |
let maskPath:UIBezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius)) | |
let maskLayer:CAShapeLayer = CAShapeLayer() | |
maskLayer.frame = bounds | |
maskLayer.path = maskPath.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
require 'fileutils' | |
from = ARGV[0] | |
to = ARGV[1] | |
# Max source directory size set to 100gb | |
maxSourceSize = 107374182400 | |
def directory_size(path) | |
path << '/' unless path.end_with?('/') |
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 ToggleHiddenLabel:UILabel { | |
var heightConstraint:NSLayoutConstraint! | |
var visible:Bool = false { | |
didSet { | |
if visible { | |
self.removeConstraint(self.heightConstraint) | |
self.hidden = false | |
} else { | |
self.addConstraint(self.heightConstraint) |
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 CustomTabbar:UITabBarController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let data = [ | |
1:"data", | |
2:"data", | |
3:"data", | |
4:"data" |
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
// BackgroundLocation.swift | |
import Foundation | |
class LocationManger : NSObject, CLLocationManagerDelegate { | |
static let sharedManager = LocationManger() | |
var locationManager:CLLocationManager! | |
var lastTimestamp:NSDate! |
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
var timer:Timer! | |
var degree = 0 | |
@objc func rotate() { | |
// assumes google map called 'map' | |
self.map.animate(toBearing: CLLocationDirection(degree)) | |
if degree == 360 { | |
timer.invalidate() // comment out this line for continual rotation | |
degree = 0 | |
} | |
degree += 18 |
OlderNewer