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 UIColor { | |
static func adapt(lightModeColor: UIColor?, darkModeColor: UIColor?) -> UIColor { | |
guard let lightModeColor = lightModeColor, | |
let darkModeColor = darkModeColor else { | |
fatalError("No color") | |
} | |
if #available(iOS 13, *) { | |
return UIColor { (traitCollection: UITraitCollection) -> UIColor in | |
if traitCollection.userInterfaceStyle == .dark { | |
/// Return the color for Dark Mode |
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 Collection { | |
/// Returns the element at the specified index if it is within bounds, otherwise nil. | |
subscript(safe index: Index) -> Element? { | |
indices.contains(index) ? self[index] : nil | |
} | |
} |
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
import Kingfisher | |
import UIKit | |
extension UIImageView { | |
static func clearImageCache() { | |
KingfisherManager.shared.cache.clearMemoryCache() | |
KingfisherManager.shared.cache.clearDiskCache() | |
} | |
/// UIImageView+: Method for downloading image |
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
import UIKit | |
final class AppearanceManager { | |
static let shared = AppearanceManager() | |
private init () {} | |
func setDefaultAppearance() { | |
// Removes all navigation bar back button title | |
UIBarButtonItem.appearance().setTitleTextAttributes( |
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 MyViewController: UITextFieldDelegate { | |
func textFieldShouldReturn(_ textField: UITextField) -> Bool { | |
// Try to find next responder | |
if let nextTextField = textField.superview?.viewWithTag(textField.tag + 1) as? UITextField { | |
nextTextField.becomeFirstResponder() | |
} else { | |
// Not found, so remove keyboard | |
textField.resignFirstResponder() | |
} | |
// Do not add a line break |
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 UIViewController { | |
func hideKeyboardWhenTappedAround() { | |
let tap = UITapGestureRecognizer( | |
target: self, | |
action: #selector(dismissKeyboard) | |
) | |
tap.cancelsTouchesInView = false | |
view.addGestureRecognizer(tap) | |
} |
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
disabled_rules: | |
excluded: | |
- Pods | |
- ProjectX/Supporting Files/R.generated.swift # R.swift | |
opt_in_rules: | |
- anyobject_protocol | |
- array_init | |
- attributes |
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
// | |
// UIView+Layout.swift | |
// Project X | |
// | |
// Created by Brian Voong on 2/10/19. | |
// Copyright © 2019 Brian Voong. All rights reserved. | |
// | |
import UIKit |
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
@objc | |
private func handleGet(_ sender: UIButton) { | |
var superview = sender.superview | |
while superview != nil { | |
if let cell = superview as? UICollectionViewCell { | |
guard let indexPath = collectionView.indexPath(for: cell), | |
let objectIClickedOnto = diffableDataSource.itemIdentifier(for: indexPath) else { return } | |
var snapshot = diffableDataSource.snapshot() | |
snapshot.deleteItems([objectIClickedOnto]) | |
diffableDataSource.apply(snapshot) |
OlderNewer