Skip to content

Commit

Permalink
Extension cleanup (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews committed Dec 18, 2023
1 parent c9fc505 commit e697b13
Show file tree
Hide file tree
Showing 59 changed files with 454 additions and 393 deletions.
484 changes: 306 additions & 178 deletions Mlem.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Array - Move Elements Around.swift
// Array+MoveElements.swift
// Mlem
//
// Created by David Bureš on 07.05.2023.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Array - Prepend.swift
// Array+Prepend.swift
// Mlem
//
// Created by David Bureš on 07.05.2023.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import Foundation

extension Array {
public subscript(safeIndex index: Int) -> Element? {
public extension Array {
subscript(safeIndex index: Int) -> Element? {
guard index >= 0, index < endIndex else {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Bundle - Current App Icon.swift
// Bundle+IconFileName.swift
// Mlem
//
// Created by tht7 on 28/06/2023.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Bundle.swift
// Bundle+VersionNumbers.swift
// Mlem
//
// Created by Jake Shirley on 6/23/23.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Color.swift
// Color+Colors.swift
// Mlem
//
// Created by David Bureš on 26.03.2022.
Expand All @@ -19,14 +19,3 @@ extension Color {
static let downvoteColor = Color.red
static let saveColor = Color.green
}

public extension Color {
static func random(randomOpacity: Bool = false) -> Color {
Color(
red: .random(in: 0 ... 1),
green: .random(in: 0 ... 1),
blue: .random(in: 0 ... 1),
opacity: randomOpacity ? .random(in: 0 ... 1) : 1
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Date.swift
// Date+RelativeTime.swift
// Mlem
//
// Created by Jake Shirley on 6/22/23.
Expand Down
14 changes: 0 additions & 14 deletions Mlem/Extensions/Dictionary - Append.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Double.swift
// Double+MaxZIndex.swift
// Mlem
//
// Created by Bosco Ho on 2023-08-07.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Environment+AppFlow.swift
// EnvironmentValues+AppFlow.swift
// Mlem
//
// Created by mormaer on 08/09/2023.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// View - EasterFlags.swift
// EnvironmentValues+EasterFlagSetter.swift
// Mlem
//
// Created by tht7 on 14/07/2023.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// EnvironmentValues+NavigationPath.swift
// Mlem
//
// Created by Eric Andrews on 2023-12-16.
//

import Foundation
import SwiftUI

private struct NavigationPathGetter: EnvironmentKey {
static let defaultValue: Binding<NavigationPath> = .constant(NavigationPath())
}

extension EnvironmentValues {
var navigationPath: Binding<NavigationPath> {
get { self[NavigationPathGetter.self] }
set { self[NavigationPathGetter.self] = newValue }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// EnvironmentValues+NavigationPathWithRoutes.swift
// Mlem
//
// Created by tht7 on 22/06/2023.
//

import Foundation
import SwiftUI

private struct NavigationPathWithRoutes: EnvironmentKey {
static let defaultValue: Binding<[AppRoute]> = .constant([])
}

extension EnvironmentValues {
var navigationPathWithRoutes: Binding<[AppRoute]> {
get { self[NavigationPathWithRoutes.self] }
set { self[NavigationPathWithRoutes.self] = newValue }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Environment+ScrollViewReaderProxy.swift
// EnvironmentValues+ScrollViewReaderProxy.swift
// Mlem
//
// Created by Bosco Ho on 2023-09-12.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FancyTabBarReselectionEnvironmentKey.swift
// EnvironmentValues+TabReselectionHashValue.swift
// Mlem
//
// Created by Eric Andrews on 2023-11-02.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FancyTabBarSelectionEnvironmentKey.swift
// EnvironmentValues+TabSelectionHashValue.swift
// Mlem
//
// Created by Eric Andrews on 2023-07-17.
Expand Down
File renamed without changes.
20 changes: 0 additions & 20 deletions Mlem/Extensions/Image.swift

This file was deleted.

23 changes: 0 additions & 23 deletions Mlem/Extensions/Int.swift

This file was deleted.

File renamed without changes.
35 changes: 0 additions & 35 deletions Mlem/Extensions/Navigation getter.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// OperationQueue - Easy init.swift
// OperationQueue+ConvenienceInit.swift
// Mlem
//
// Created by tht7 on 08/07/2023.
Expand Down
33 changes: 0 additions & 33 deletions Mlem/Extensions/String.swift

This file was deleted.

14 changes: 14 additions & 0 deletions Mlem/Extensions/String/String+Alphabet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// String+Alphabet.swift
// Mlem
//
// Created by Eric Andrews on 2023-12-16.
//

import Foundation

extension [String] {
static var alphabet: Self {
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// String - Contains Elements From Array.swift
// String+Contains.swift
// Mlem
//
// Created by David Bureš on 04.05.2023.
Expand Down
14 changes: 14 additions & 0 deletions Mlem/Extensions/String/String+IsNotEmpty.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// String+IsNotEmpty.swift
// Mlem
//
// Created by Eric Andrews on 2023-12-16.
//

import Foundation

extension String {
var isNotEmpty: Bool {
!isEmpty
}
}
14 changes: 14 additions & 0 deletions Mlem/Extensions/String/String+Trimmed.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// String+Trimmed.swift
// Mlem
//
// Created by Eric Andrews on 2023-12-16.
//

import Foundation

extension String {
var trimmed: String {
trimmingCharacters(in: .whitespacesAndNewlines)
}
}
19 changes: 19 additions & 0 deletions Mlem/Extensions/String/String+WithEscapedCharacters.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// String+WithEscapedCharacters.swift
// Mlem
//
// Created by Eric Andrews on 2023-12-16.
//

import Foundation

extension String {
func withEscapedCharacters() -> String? {
do {
let jsonRepresentation = try JSONEncoder().encode(self)
return String(data: jsonRepresentation, encoding: .utf8)
} catch {
return nil
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// UIApplication - First Key Window.swift
// UIApplication+FirstKeyWindow.swift
// Mlem
//
// Created by David Bureš on 18.05.2023.
Expand All @@ -16,8 +16,4 @@ extension UIApplication {
.first?
.keyWindow
}

var topMostViewController: UIViewController? {
UIApplication.shared.firstKeyWindow?.rootViewController?.topMostViewController()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// UIApplication+TopMostViewController.swift
// Mlem
//
// Created by Eric Andrews on 2023-12-16.
//

import Foundation
import UIKit

extension UIApplication {
var topMostViewController: UIViewController? {
UIApplication.shared.firstKeyWindow?.rootViewController?.topMostViewController()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// UIUserInterfaceStyle - SettingsOption conformant.swift
// UIUserInterfaceStyle+SettingsOptions.swift
// Mlem
//
// Created by Eric Andrews on 2023-06-19.
Expand Down
Loading

0 comments on commit e697b13

Please sign in to comment.