Skip to content

Commit

Permalink
organized and renamed extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews committed Dec 17, 2023
1 parent 886150a commit 26047e5
Show file tree
Hide file tree
Showing 55 changed files with 402 additions and 341 deletions.
462 changes: 295 additions & 167 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
File renamed without changes.
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
Expand Up @@ -8,21 +8,6 @@
import Foundation
import SwiftUI

// MARK: - SwiftUI.NavigationPath

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 }
}
}

// MARK: - Mlem NavigationRoute

private struct NavigationPathWithRoutes: EnvironmentKey {
static let defaultValue: Binding<[AppRoute]> = .constant([])
}
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.
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"]
}
}
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
Expand Up @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions Mlem/Extensions/URLSessionWebSocketTask - Send Ping.swift

This file was deleted.

21 changes: 0 additions & 21 deletions Mlem/Extensions/View - Hide View.swift

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import SwiftUI

// TODO: iOS 16 deprecation remove this
extension View {

/// No-op prior to iOS 16.4.
func _presentationBackgroundInteraction(enabledUpThrough detent: PresentationDetent) -> some View {
if #available(iOS 16.4, *) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 26047e5

Please sign in to comment.