Thanks for the reply. I wasn't sure how much code to show. Yes, I want to select multiple items and then have another view to sort them. And by sorting I mean I want the user to be able to drag them into the order desired. I should have made that clear.
I'll look into your suggestions.
Post
Replies
Boosts
Views
Activity
Thanks again. I see I've made a mess of trying to explain my problem. I have code that can do the sort and it looks pretty much like yours. And I have code that selects multiple items, but it's pretty long, which is why I didn't include it.
The problem is the multi-select view uses an array of language codes and the sort/arrange uses an array that's identifiable so it has the UUID in it as well. I don't know how to change my code to use the same var in each view, nor do I know how to take the array of selections and use it to populate the identifiable array. Every way I try, I get cryptic errors.
Maybe instead of referencing my code, I should just ask how can I let the user select multiple items and then arrange those items in the desired order?
Thanks for the reply. I had thought that parsing the xml would be hard part but it turned out to be the easiest part of this little app so far. By contrast, I've spent days just trying to figure out how to do what I thought would be a simple http request. I just can't find sample code to do what I want to do. I know that the problem is the network reply is coming back after the function returns, I just don't know how to tell it to wait. Based on your reply I've now come up with this:
func doHttpCall(st : String) async -> String {
var xmlData = ""
let url = URL(string: st)!
let urlRequest = URLRequest(url: url)
do {
let (data, _) = try await URLSession.shared.data(for: urlRequest)
xmlData = String(data: data, encoding: .utf8)!
print(xmlData)
}
catch {
print("error")
}
return xmlData
}
That gives me the error: 'async' call in a function that does not support concurrency.
Is there any chance you could point me to some sample code or app that does what I want? I find I learn best from seeing sample code rather that trying to read the documentation.
Thanks again.
I think I finally found a workable solution. I kept searching and found some code that uses semaphores and incorporated it into my original function and it seems to work.
func doHttpCall(st : String) -> String {
var xmlStr = ""
let url = URL(string: st)!
let semaphore = DispatchSemaphore(value: 0)
let task = URLSession.shared.dataTask(with: url, completionHandler: {(data, response, error) in
if let error = error {
print("Error: \(error)")
} else if let response = response as? HTTPURLResponse,
300..<600 ~= response.statusCode {
print("Error: \(response.statusCode)")
} else {
let mydata = data!
xmlStr = String(data: mydata, encoding: .utf8)!
print(xmlStr)
}
semaphore.signal()
})
task.resume()
_ = semaphore.wait(timeout: DispatchTime.distantFuture)
return xmlStr
}
And I even understand what it's doing.
If you have a better solution, I'll always be happy to see it. But sending an http request and getting a response is just an incidental but necessary part of my little app. It only took me a week to find a solution. Thanks again for your trouble.