Skip to content

Instantly share code, notes, and snippets.

Avatar
🥝
Working...

Maksym Bilan maximbilan

🥝
Working...
View GitHub Profile
View UIView+XIB.swift
public extension UIView {
class func fromNib<T: UIView>() -> T {
return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T
}
}
@maximbilan
maximbilan / SwiftyAccountKit.swift
Created Aug 12, 2017
SwiftyAccountKit - Facebook AccountKit Swift Wrapper
View SwiftyAccountKit.swift
//
// SwiftyAccountKit.swift
// SwiftyAccountKit
//
// Created by Maxim on 7/13/17.
// Copyright © 2017 Maxim Bilan. All rights reserved.
//
import AccountKit
@maximbilan
maximbilan / Trim.swift
Created Feb 10, 2017
Swift 3 Trimming of special characters
View Trim.swift
extension String {
func trim(_ string: String) -> String {
var set = Set<Character>()
for c in string.characters {
set.insert(Character(String(c)))
}
return trim(set)
}
@maximbilan
maximbilan / AmazonS3Uploader.swift
Created Feb 10, 2017
Swift 3 Upload file to Amazon S3 with pre-signed link
View AmazonS3Uploader.swift
func upload(data: Data, urlString: String, mimeType: String, completion: @escaping (Bool, Error?) -> Void) {
let requestURL = URL(string: urlString)!
let client = AFHTTPSessionManager(baseURL: requestURL)
var request = URLRequest(url: requestURL)
request.httpMethod = "PUT"
request.httpBody = data
request.setValue(mimeType, forHTTPHeaderField: "Content-Type")
request.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
request.setValue("public-read", forHTTPHeaderField: "x-amz-acl")
let task = client?.dataTask(with: request, completionHandler: { (response, responseObject, error) in
View DateISO8601.swift
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 Jul 24, 2016
UITextView Placeholder Example
View UITextViewPlaceholder.swift
import UIKit
class ViewController: UIViewController {
let placeholder = "Placeholder"
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
View InstagramWallPost.swift
let image = UIImage(named: "example")
let instagramURL = NSURL(string: "instagram://app")
if UIApplication.sharedApplication().canOpenURL(instagramURL!) {
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let saveImagePath = (documentsPath as NSString).stringByAppendingPathComponent("Image.igo")
let imageData = UIImagePNGRepresentation(image!)
do {
try imageData?.writeToFile(saveImagePath, options: NSDataWritingOptions(rawValue: 0))
} catch {
print("Instagram sharing error")
@maximbilan
maximbilan / NSLayoutConstraintMultiplierExtension.swift
Created Jul 21, 2016
NSLayoutConstraint Multiplier Extension
View NSLayoutConstraintMultiplierExtension.swift
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 Jul 16, 2016
Swift Quick Internet Availability Check
View ConnectionCheck.swift
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))
View EmailValidation.swift
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)
}