Skip to content

Instantly share code, notes, and snippets.

View maximbilan's full-sized avatar
🧑‍🚒
Working...

Maksym Bilan maximbilan

🧑‍🚒
Working...
View GitHub Profile
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"
@maximbilan
maximbilan / UITextViewPlaceholder.swift
Created July 24, 2016 06:53
UITextView Placeholder Example
import UIKit
class ViewController: UIViewController {
let placeholder = "Placeholder"
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
@maximbilan
maximbilan / NSLayoutConstraintMultiplierExtension.swift
Created July 21, 2016 12:51
NSLayoutConstraint Multiplier Extension
extension NSLayoutConstraint {
func setMultiplier(multiplier:CGFloat) -> NSLayoutConstraint {
let newConstraint = NSLayoutConstraint(
item: firstItem,
attribute: firstAttribute,
relatedBy: relation,
toItem: secondItem,
attribute: secondAttribute,
@maximbilan
maximbilan / ConnectionCheck.swift
Created July 16, 2016 09:21
Swift Quick Internet Availability Check
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))
@maximbilan
maximbilan / UIViewExtension.swift
Created September 11, 2015 10:24
Swift 2.0 Simple extension for loading UIView with XIB
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 {
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)
}
#
# 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:
@maximbilan
maximbilan / CenterViewFlowLayout.swift
Created February 7, 2016 13:41
CenterViewFlowLayout
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
@maximbilan
maximbilan / gist:b7a747eb9a56a5d5e54b
Created February 6, 2016 10:50
iCloudIssue.swift
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")
import UIKit
public enum DeviceSpecific {
case iPhone
case iPhoneRetina
case iPhone5
case iPhone6
case iPhone6Plus
case iPad
case iPadRetina