This file contains 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
# 1) | |
# ...Parse a configuration file... | |
schemes = parse(file: "config.json") | |
# 2) | |
for scheme in schemes do | |
# 3) | |
# Provide environment variables for sigh using the current `scheme` object | |
# ... | |
# ENV["SIGH_USERNAME"] = scheme["apple_id"] |
This file contains 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
class KeyboardAwareViewController: UIViewController, KeyboardAvoidable { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupKeyboardNotifications() | |
} | |
deinit { | |
removeKeyboardNotifications() | |
} | |
} |
This file contains 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
//MARK: - Private | |
fileprivate extension KeyboardAvoidable where Self: UIViewController { | |
func keyboardWillAppear(_ notification: Notification) { | |
//1 | |
let keyboardInfo = KeyboardNotification(notification) | |
let duration = keyboardInfo.animationDuration | |
let curve = keyboardInfo.animationCurve | |
let keyboardEndFrame = keyboardInfo.keyboardFrameEnd | |
This file contains 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
//MARK: - Public | |
extension KeyboardAvoidable where Self: UIViewController { | |
func setupKeyboardNotifications() { | |
NotificationCenter.default.addObserver(forName: .UIKeyboardWillShow, object: nil, queue: nil, using: { | |
[weak self] notification in | |
//Had to use block because protocols don't understand selectors | |
//Therefore whoever conforms to `KeyboardAvoidable` needs to call `removeKeyboardNotifications` in deinit | |
self?.keyboardWillAppear(notification) | |
}) | |
This file contains 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
protocol KeyboardAvoidable: class { | |
var keyboardOpen: Bool { get set } | |
} |
This file contains 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
extension NSAttributedString { | |
func align(_ alignment: NSTextAlignment) -> NSAttributedString { | |
//1 | |
guard !string.isEmpty else { return self } | |
//2 | |
let mutable = mutableCopy() as! NSMutableAttributedString | |
//3 |
This file contains 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
"Style me" | |
.toAttributedString() | |
.medium(sized: 16) | |
.colored(.orange) |
This file contains 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
extension NSAttributedString { | |
func medium(sized size: CGFloat) -> NSAttributedString { | |
//1 | |
guard !string.isEmpty else { return } | |
//2 | |
let mutable = mutableCopy() as! NSMutableAttributedString | |
//3 |
This file contains 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
extension String { | |
func toAttributedString() -> NSAttributedString { | |
return NSAttributedString(string: self) | |
} | |
} | |
//Example Usage | |
"Convert me please".toAttributedString() |
This file contains 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
let attributes: [String : Any] = [ | |
NSFontAttributeName : UIFont(name: "AvenirNext-Medium", size: 16), | |
NSForegroundColorAttributeName : UIColor.orange | |
] | |
let label = UILabel() | |
label.attributedText = NSAttributedString(string: "Style me", attributes: attributes) |
NewerOlder