-1

With the code below, I want to print query items into textview, but only the last query appears. When I print it on the console, all are visible.

let url = URL(string: inputURL.string)!
    let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
    if let components = components {
        if let queryItems = components.queryItems {
            for queryItem in queryItems {
                outputURL.string = "\(queryItem.name) = \(queryItem.value ?? "")"
                print("\(queryItem.name) = \(queryItem.value ?? "")")
            }
        }
    }

1 Answers1

1

You are overwriting your NSTextView each time you iterate through your loop.

Change this:

outputURL.string = "\(queryItem.name) = \(queryItem.value ?? "")"

to this:

outputURL.string.append ("\(queryItem.name) = \(queryItem.value ?? "")")

Woodstock
  • 22,184
  • 15
  • 80
  • 118