This file contains hidden or 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
/// Classes whose initializers actually create derived classes | |
protocol FactoryInitializable { | |
/// The type of the least-derived class declared to be FactoryInitializable. | |
/// | |
/// - Warning: Do not define this in your FactoryInitializable type! | |
associatedtype FactoryBase: AnyObject, FactoryInitializable = Self | |
// This associatedtype is a trick that captures `Self` at the point where | |
// `FactoryInitializable` enters a class hierarchy; in other contexts, `Self` | |
// refers to the most-derived type. | |
} |
This file contains hidden or 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
// Swift4 | |
let image = UIImage(named: "sample") | |
let data = image?.pngData() | |
let data = image?.jpegData(compressionQuality: 0.9) | |
let uiImage: UIImage = UIImage(data: imageData) | |
// deprecated | |
// var imageData: Data = UIImagePNGRepresentation(image) |
This file contains hidden or 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
precedencegroup BooleanPrecedence { associativity: left } | |
infix operator ^^ : BooleanPrecedence | |
/** | |
Swift Logical XOR operator | |
``` | |
true ^^ true // false | |
true ^^ false // true | |
false ^^ true // true | |
false ^^ false // false | |
``` |
This file contains hidden or 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
// | |
// ViewController.swift | |
// SnapKitTest | |
// | |
// Created by Robert Payne on 10/11/15. | |
// Copyright © 2015 Zwopple Limited. All rights reserved. | |
// | |
import SnapKit | |
import UIKit |
This file contains hidden or 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
func keyboardWillShow(notification: NSNotification) { | |
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { | |
let contentInsets = UIEdgeInsets(top: self.tableView.contentInset.top, left: 0, bottom: keyboardSize.height, right: 0) | |
self.tableView.contentInset = contentInsets | |
// If active text field is hidden by keyboard, scroll it so it's visible | |
// Your app might not need or want this behavior. | |
var aRect: CGRect = self.view.frame | |
aRect.size.height -= keyboardSize.height | |
let activeTextFieldRect: CGRect? |