-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update some code - Update mini support version to iOS 15 Co-authored-by: James Layton <>
- Loading branch information
1 parent
3f1210e
commit 335f3ef
Showing
11 changed files
with
235 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
18 changes: 18 additions & 0 deletions
18
Sources/JimUtilitySDK/Extensions/Data/PrettyPrintedJSONString.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// PrettyPrintedJSONString.swift | ||
// | ||
// | ||
// Created by James Layton on 7/11/24. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Data { | ||
var prettyPrintedJSONString: NSString? { | ||
guard let object = try? JSONSerialization.jsonObject(with: self, options: []), | ||
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]), | ||
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil } | ||
|
||
return prettyPrintedString | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Sources/JimUtilitySDK/Extensions/String/FormattedDecimalNumber.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// FormattedDecimalNumber.swift | ||
// | ||
// | ||
// Created by James Layton on 7/11/24. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension String { | ||
func FormattedDecimalNumber(_ maximumFractionDigits: Int = 0) -> String? { | ||
guard let number = Double(self) else { return nil } | ||
|
||
let formatter = NumberFormatter() | ||
formatter.numberStyle = .decimal | ||
formatter.maximumFractionDigits = maximumFractionDigits // Optional: Adjust if you want to show decimals | ||
|
||
return formatter.string(from: NSNumber(value: number)) | ||
} | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...tensions/String/String+isValidEmail.swift → ...ySDK/Extensions/String/IsValidEmail.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// String+isValidEmail.swift | ||
// IsValidEmail.swift | ||
// | ||
// | ||
// Created by James Layton on 6/21/20. | ||
|
2 changes: 1 addition & 1 deletion
2
...sions/String/String+isValidPassword.swift → ...K/Extensions/String/IsValidPassword.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// File.swift | ||
// IsValidPassword.swift | ||
// | ||
// | ||
// Created by James Layton on 1/17/23. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// HideKeyboard.swift | ||
// | ||
// | ||
// Created by James Layton on 7/11/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension View { | ||
func hideKeyboard() { | ||
let resign = #selector(UIResponder.resignFirstResponder) | ||
UIApplication.shared.sendAction(resign, to: nil, from: nil, for: nil) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Sources/JimUtilitySDK/Extensions/View/NavigationBarColor.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// NavigationBarColor.swift | ||
// | ||
// | ||
// Created by James Layton on 7/11/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct NavigationBarColorModifier: ViewModifier { | ||
var backgroundColor: UIColor? | ||
|
||
init(backgroundColor: UIColor?) { | ||
self.backgroundColor = backgroundColor | ||
let appearance = UINavigationBarAppearance() | ||
appearance.backgroundColor = backgroundColor | ||
appearance.titleTextAttributes = [.foregroundColor: UIColor.white] | ||
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white] | ||
UINavigationBar.appearance().standardAppearance = appearance | ||
UINavigationBar.appearance().scrollEdgeAppearance = appearance | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
} | ||
} | ||
|
||
public extension View { | ||
func navigationBarColor(_ backgroundColor: UIColor?) -> some View { | ||
self.modifier(NavigationBarColorModifier(backgroundColor: backgroundColor)) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Sources/JimUtilitySDK/Extensions/View/OnFirstAppearOrTask.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// OnFirstAppearOrTask.swift | ||
// | ||
// | ||
// Created by James Layton on 7/11/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension View { | ||
func onFirstAppear(_ action: @escaping () -> Void) -> some View { | ||
modifier(FirstAppear(action: action)) | ||
} | ||
|
||
func onFirstTask(_ action: @escaping () async -> Void) -> some View { | ||
modifier(FirstTask(action: action)) | ||
} | ||
} | ||
|
||
private struct FirstAppear: ViewModifier { | ||
let action: () -> Void | ||
|
||
// Use this to only fire your block one time | ||
@State private var hasAppeared = false | ||
|
||
func body(content: Content) -> some View { | ||
// And then, track it here | ||
content.onAppear { | ||
guard !hasAppeared else { return } | ||
hasAppeared = true | ||
action() | ||
} | ||
} | ||
} | ||
|
||
private struct FirstTask: ViewModifier { | ||
let action: () async -> Void | ||
|
||
// Use this to only fire your block one time | ||
@State private var hasAppeared = false | ||
|
||
func body(content: Content) -> some View { | ||
// And then, track it here | ||
content.onAppear { | ||
guard !hasAppeared else { return } | ||
hasAppeared = true | ||
|
||
Task { | ||
await action() | ||
} | ||
} | ||
} | ||
} |