Skip to content

Instantly share code, notes, and snippets.

View nurtugan's full-sized avatar
🏠
Working from home

Nurtugan Nuraly nurtugan

🏠
Working from home
View GitHub Profile
@nurtugan
nurtugan / SafeSubscriptingOfCollection.swift
Created March 11, 2020 09:53
Safe subscripting of Collection
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
}
}
@nurtugan
nurtugan / RemoveNavigationBarBackBarButtonItemTitle.swift
Created March 10, 2020 05:01
Removes NavigationBar's BackBarButtonItem Title
extension UIViewController {
func removeNavigationBarBackBarButtonItemTitle() {
let backButton = UIBarButtonItem()
backButton.title = ""
navigationController?.navigationBar.topItem?.backBarButtonItem = backButton
}
}
@nurtugan
nurtugan / UIColor+.swift
Created March 8, 2020 14:52
Dark mode color adapter
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