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 Date { | |
struct Formatter { | |
static let iso8601: DateFormatter = { | |
let formatter = DateFormatter() | |
formatter.calendar = Calendar(identifier: .iso8601) | |
formatter.locale = Locale.current | |
formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX" |
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 | |
class ViewController: UIViewController { | |
let placeholder = "Placeholder" | |
@IBOutlet weak var textView: UITextView! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
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 NSLayoutConstraint { | |
func setMultiplier(multiplier:CGFloat) -> NSLayoutConstraint { | |
let newConstraint = NSLayoutConstraint( | |
item: firstItem, | |
attribute: firstAttribute, | |
relatedBy: relation, | |
toItem: secondItem, | |
attribute: secondAttribute, |
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 SystemConfiguration | |
public class Reachability { | |
class func isConnectedToNetwork() -> Bool { | |
var zeroAddress = sockaddr_in() | |
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress)) | |
zeroAddress.sin_family = sa_family_t(AF_INET) | |
let defaultRouteReachability = withUnsafePointer(&zeroAddress) { | |
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($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
import UIKit | |
public extension UIView { | |
public class func instantiateFromNib<T: UIView>(viewType: T.Type) -> T { | |
let url = NSURL(string: NSStringFromClass(viewType)) | |
return NSBundle.mainBundle().loadNibNamed(url?.pathExtension, owner: nil, options: nil).first as! T | |
} | |
public class func instantiateFromNib() -> Self { |
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 Foundation | |
extension String { | |
func isValidEmail() -> Bool { | |
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}" | |
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx) | |
return emailTest.evaluateWithObject(self) | |
} |
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
# | |
# c.f. StackOverflow question/answer here: http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4 | |
# | |
# Version 2.5 | |
# | |
# Latest Change: | |
# - The "copy headers" section now respects the build setting for the location of the public headers | |
# - Opens the directory with the universal library after build (Can be annoying) | |
# | |
# Purpose: |
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 | |
class CenterViewFlowLayout: UICollectionViewFlowLayout { | |
override func collectionViewContentSize() -> CGSize { | |
// Only support single section for now. | |
// Only support Horizontal scroll | |
let count = self.collectionView?.dataSource?.collectionView(self.collectionView!, numberOfItemsInSection: 0) | |
let canvasSize = self.collectionView!.frame.size | |
var contentSize = canvasSize |
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 directories = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) | |
if let documentDirectory = directories.first { | |
do { | |
let documents = try NSFileManager.defaultManager().contentsOfDirectoryAtPath(documentDirectory) | |
for files in documents { | |
let urlForm = NSURL.fileURLWithPath(documentDirectory + "/" + files) | |
do { | |
try print("\(files): \(urlForm.resourceValuesForKeys([NSURLIsExcludedFromBackupKey]))") | |
} catch { | |
print("can't find key") |
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 | |
public enum DeviceSpecific { | |
case iPhone | |
case iPhoneRetina | |
case iPhone5 | |
case iPhone6 | |
case iPhone6Plus | |
case iPad | |
case iPadRetina |