Thank you for your reply. In my case what needs to be enumerated are four iPhones connected to a MacStudio by means of Lightning Cable. I am attempting to enumerate these to establish communications with software also written by me in the iPhones.
I did the conversion you recommended. But when I attempt to use my equivalent of your "newResultsArray" in a View's ForEach statement I find that something is lost in the conversion. When I attempt to use my equivalent, which in my code is the results member of the SSH_Browser class (code below), I get an error in the View. What was lost? What needs to be done to get the print function to accept it?
The code, and the error message in comments:
struct ContentView: View {
@StateObject var sshBrowser = SSH_Browser()
var body: some View {
VStack {
ForEach( sshBrowser.results, id:\.hashValue ) { result in
print("result ", result ) // Red underline under the first character of "print(...". The error: "No exact matches in reference to static method 'buildExpression'"
}
}
.padding()
}
}
class SSH_Browser: ObservableObject {
var browser: NWBrowser!
@Published var results: [NWBrowser.Result] = []
init() {
let bonjourTCP = NWBrowser.Descriptor.bonjour(type: "_ssh._tcp" , domain: nil)
let bonjourParms = NWParameters.init()
browser = NWBrowser(for: bonjourTCP, using: bonjourParms)
// This change event handler code executes when available devices change.
browser.browseResultsChangedHandler = { ( results, changes ) in
for result in results {
print("result ", result ) // No error here. The "result" Set element is accepted.
if case .service(let service) = result.endpoint {
print("bonjourA ", service.name)
}
}
self.results = Array( results ) // Something is lost here, for when used in the View the print() function does not accept the self.results array elements.
}
browser.start(queue: DispatchQueue.main)
}
}