Skip to content

Commit

Permalink
Merge pull request #87 from kishikawakatsumi/port
Browse files Browse the repository at this point in the history
Fix port validation
  • Loading branch information
kishikawakatsumi authored Jul 27, 2024
2 parents b80fa0e + 6743588 commit 6ff42dd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Examples/FileBrowser/FileBrowser (iOS)/ConnectServerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ConnectServerView: View {
@State private var password: String

private var canSubmit: Bool {
!server.isEmpty && !username.isEmpty && !password.isEmpty
!server.isEmpty && (port.isEmpty || Int(port) != nil ) && !username.isEmpty && !password.isEmpty
}

@FocusState
Expand Down Expand Up @@ -81,6 +81,7 @@ struct ConnectServerView: View {
TextField("Port", text: $port)
.multilineTextAlignment(.trailing)
.focused($focusedField, equals: .port)
.keyboardType(.numberPad)
} label: {
Text("Port")
}
Expand Down Expand Up @@ -133,7 +134,12 @@ struct ConnectServerView: View {
private func submit() {
Task { @MainActor in
do {
let client = SMBClient(host: server, port: Int(port)!)
let client: SMBClient
if let port = Int(port) {
client = SMBClient(host: server, port: port)
} else {
client = SMBClient(host: server)
}
try await client.login(username: username, password: password)

dismiss()
Expand Down

0 comments on commit 6ff42dd

Please sign in to comment.