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 | |
} | |
} |
View SwiftyAccountKit.swift
// | |
// SwiftyAccountKit.swift | |
// SwiftyAccountKit | |
// | |
// Created by Maxim on 7/13/17. | |
// Copyright © 2017 Maxim Bilan. All rights reserved. | |
// | |
import AccountKit |
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) | |
} | |
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" |
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") |
View NSLayoutConstraintMultiplierExtension.swift
extension NSLayoutConstraint { | |
func setMultiplier(multiplier:CGFloat) -> NSLayoutConstraint { | |
let newConstraint = NSLayoutConstraint( | |
item: firstItem, | |
attribute: firstAttribute, | |
relatedBy: relation, | |
toItem: secondItem, | |
attribute: secondAttribute, |
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) | |
} |
NewerOlder