(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| // add .identifier | |
| let centerXConstraint = view.centerXAnchor.constraint(equalTo: centerXAnchor, constant: 0) | |
| centerXConstraint.identifier = "IdentifierName" | |
| // get constraint | |
| let constraintByIdentifier = view.constraints.filter ({ $0.identifier == "IdentifierName" }).first |
| # taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/ | |
| # generate server.xml with the following command: | |
| # openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes | |
| # run as follows: | |
| # python simple-https-server.py | |
| # then in your browser, visit: | |
| # https://localhost:4443 | |
| import BaseHTTPServer, SimpleHTTPServer | |
| import ssl |
| import Foundation | |
| enum timingFunction{ | |
| case Linear,EaseIn,EaseOut,EaseInOut, | |
| Spring, | |
| EaseInSine,EaseOutSine,EaseInOutSine, | |
| EaseInQuad,EaseOutQuad,EaseInOutQuad, | |
| EaseInCubic,EaseOutCubic,EaseInOutCubic, | |
| EaseInQuart,EaseOutQuart,EaseInOutQuart, | |
| EaseInQuint,EaseOutQuint,EaseInOutQuint, |
| import Foundation | |
| import UIKit | |
| struct ViewStyle<T> { | |
| let style: (T) -> Void | |
| } | |
| let filled = ViewStyle<UIButton> { | |
| $0.setTitleColor(.white, for: .normal) | |
| $0.backgroundColor = .red |
| xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.CoreTelephony | |
| # source: https://github.com/aws-amplify/aws-sdk-ios/issues/1251#issuecomment-471866504 |
| extension UIView { | |
| func firstSuperview<T>(where predicate: (T) -> Bool) -> T? where T: UIView { | |
| if let superview = superview as? T, predicate(superview) { | |
| return superview | |
| } | |
| return superview?.firstSuperview(where: predicate) | |
| } | |
| } | |
| // view.firstSuperview(where: { (view: UITableView) in view.isEditing }) |
| extension UIColor { | |
| // get a complementary color to this color | |
| // https://gist.github.com/klein-artur/025a0fa4f167a648d9ea | |
| var complementary: UIColor { | |
| let ciColor = CIColor(color: self) | |
| // get the current values and make the difference from white: | |
| let compRed: CGFloat = 1.0 - ciColor.red |
| //Inspired by: http://planetozh.com/blog/2012/10/generate-random-pronouceable-words/ | |
| func randomWord(wordLength: Int = 6) -> String { | |
| let kCons = 1 | |
| let kVows = 2 | |
| var cons: [String] = [ | |
| // single consonants. Beware of Q, it"s often awkward in words | |
| "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", | |
| "n", "p", "r", "s", "t", "v", "w", "x", "z", |
| let emitterLayer = CAEmitterLayer() | |
| emitterLayer.frame = navigationView.bounds | |
| emitterLayer.renderMode = .additive | |
| emitterLayer.emitterMode = .outline | |
| emitterLayer.emitterShape = .line | |
| emitterLayer.emitterSize = CGSize(width: 50, height: 0) | |
| emitterLayer.emitterPosition = CGPoint(x: navigationView.bounds.width / 2, y: navigationView.bounds.height) | |
| emitterLayer.velocity = 1 | |
| emitterLayer.seed = (arc4random() % 100) + 1 | |
| navigationView.layer.insertSublayer(emitterLayer, at: 0) |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.