This commit is contained in:
Lncvrt committed 2026-08-29 19:31:07 -07:00
1 parent f2e8e99958
commit b67c2d7ccf
1 file changed
+17 -14
+17 -14
View File
@@ -14,13 +14,13 @@ import UIKit
#endif #endif
func copyToClipboard(text: String) { func copyToClipboard(text: String) {
#if os(macOS) #if os(macOS)
let pasteboard = NSPasteboard.general let pasteboard = NSPasteboard.general
pasteboard.clearContents() pasteboard.clearContents()
pasteboard.setString(text, forType: .string) pasteboard.setString(text, forType: .string)
#else #else
UIPasteboard.general.string = text UIPasteboard.general.string = text
#endif #endif
} }
struct ContentView: View { struct ContentView: View {
@@ -38,23 +38,23 @@ struct ContentView: View {
func generatePassword() { func generatePassword() {
let chars = let chars =
(useUppercase ? charsUpper : "") + (useUppercase ? charsUpper : "") +
(useLowercase ? charsLower : "") + (useLowercase ? charsLower : "") +
(useNumbers ? charsNumber : "") + (useNumbers ? charsNumber : "") +
(useSymbols ? charsSymbols : "") (useSymbols ? charsSymbols : "")
if chars.isEmpty { if chars.isEmpty {
password = "" password = ""
return return
} }
password = String( password = String(
(0..<length).compactMap { _ in (0..<length).compactMap { _ in
chars.randomElement() chars.randomElement()
} }
) )
} }
var body: some View { var body: some View {
VStack { VStack {
Text("Password Generator") Text("Password Generator")
@@ -62,14 +62,16 @@ struct ContentView: View {
.fontWeight(.bold) .fontWeight(.bold)
Text("Select a length, or use the slider for a custom value") Text("Select a length, or use the slider for a custom value")
Text("Password Length: " + String(length)).padding(.top) Text("Password Length: " + String(length))
.padding(.top)
Slider( Slider(
value: Binding( value: Binding(
get: { Double(length) }, get: { Double(length) },
set: { length = Int($0) } set: { length = Int($0) }
), ),
in: 1...500 in: 1...500
).onChange(of: length) { generatePassword() } )
.onChange(of: length) { generatePassword() }
HStack { HStack {
Button("8") { Button("8") {
@@ -94,7 +96,8 @@ struct ContentView: View {
.buttonStyle(.bordered) .buttonStyle(.bordered)
} }
Text("Characters to use").padding() Text("Characters to use")
.padding()
LazyVGrid( LazyVGrid(
columns: [ columns: [
GridItem(.adaptive(minimum: 180)) GridItem(.adaptive(minimum: 180))
@@ -126,7 +129,7 @@ struct ContentView: View {
Text(password) Text(password)
.textSelection(.enabled) .textSelection(.enabled)
.multilineTextAlignment(.center) .multilineTextAlignment(.center)
Spacer() Spacer()
} }
.padding() .padding()