Questions tagged [nsurlcomponents]

NSURLComponents (or URLComponents in Swift) is a type that parses URLs into and constructs URLs from their constituent parts.

For more information, see the official documentation of NSURLComponents.

26 questions
58
votes
1 answer

What's the difference between passing false and true to 'resolvingAgainstBaseURL' when initialize a NSURLComponents instance?

I can't understand what's the difference between these two ways of calling: NSURLComponents(URL: url, resolvingAgainstBaseURL: true) and NSURLComponents(URL: url, resolvingAgainstBaseURL: false) And I found the explanation of documentation was…
SomeHowWhite
  • 621
  • 5
  • 9
37
votes
2 answers

URLComponents.url is nil

I'm trying to use URLComponents to compose a URL as that appears to be what it's for. However, when I then access the url property of the components it is nil. Example... var urlComponents = URLComponents(string:…
Fogmeister
  • 70,181
  • 37
  • 189
  • 274
4
votes
1 answer

What kind of URL is not conforming to RFC 3986 but is conforming to RFC 1808, RFC 1738, and RFC 2732?

The doc of URLComponents.init(url:resolvingAgainstBaseURL:) says: Returns the initialized URL components object, or nil if the URL could not be parsed. Knowing that: Swift URL/NSURL is for URLs based on RFC 1808, RFC 1738, and RFC 2732:…
Cœur
  • 32,421
  • 21
  • 173
  • 232
2
votes
2 answers

URLComponents queryItems losing percent encoding when mutated

When using URLComponents's queryItems I've found that if you have a query item whose value contains some percent encoded characters, in my case a / being encoded as %2F, then if you construct a URLComponents object from a String URL that contains…
hamchapman
  • 1,675
  • 2
  • 18
  • 36
2
votes
1 answer

Why does NSURL parse strings with a double forward slash after the scheme differently to a string with a single forward slash?

When parsing strings into NSURL objects, NSURL treats a string using a single forward slash differently to a string with a double forward slash after the scheme. Why is this the case? Here's some examples: NSURL *url = [NSURL…
Jessedc
  • 11,538
  • 3
  • 45
  • 63
1
vote
0 answers

Swift: preventing the host url component from being percent escaped automatically

I have the following two base urls for my API methods: let stagingHost = "myApi.test.com/sub1" let productionHost = "myApi.test.com/sub2" when I build the url for any API call in my app, I do the following: var components =…
JAHelia
  • 4,684
  • 14
  • 52
  • 102
1
vote
1 answer

Swift GET request with url parameters

I am building a survey where when a user answers a question I append the answers to a url string with parameters and send a get request to my server. So for every answer there is a record made of the selected answer, timestamp and unique id of the…
jfulton
  • 69
  • 10
1
vote
1 answer

URLQuery item does not grab the location coordinate

I am wondering what can the be reason of my issue. I am using core location in order to get the my coordinates location, which I use in the network method as a URLQueryItem in order to get a response from the API. But the console output shows that…
Vangola
  • 116
  • 7
1
vote
1 answer

URLComponents finding nil

So my condition here is that if the URL is contained com://******/sendto/webview then it should open in a browser inside my app or else it will open in Safari. I can't figure out what am I doing wrong? if let url = homeObject["deeplink_url"]…
1
vote
1 answer

In Swift Convert [String: Any!] to URLComponents

I'm having a dictionary [String: Any!] that has values like integers, floats and strings. When I'm creating URLComponents using below code, its not taking values related to integers and floats. func queryItems(dictionary: [String: Any]) ->…
Satyam
  • 14,636
  • 29
  • 122
  • 234
0
votes
1 answer

NSURLComponent is not giving right URL when IP address exist in URL

My NSURLComponents is translating '/' to '%2F'. Please see log after 10.32.135.10. NSURLComponents *urlComponent = [[NSURLComponents alloc] init]; [urlComponent setScheme:@"http"]; [urlComponent setHost:@"10.32.135.10/test.API"]; [urlComponent…
0
votes
0 answers

Expression Working in debugger but not in code

So here's my code: let queryItems = [URLQueryItem(name: "foo", value: "bar")] var urlComponents = URLComponents(string: "http://example.com/fiz") urlComponents?.queryItems = queryItems print(urlComponents?.url?.absoluteString) The printed string…
0
votes
1 answer

Query keys are encoded in URLComponent's url

I'm using URLQueryItem to encode query values but when I pass queries to the URLComponent in the url property query keys are encoded too. var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) urlComponents.queryItems =…
Maysam
  • 6,738
  • 13
  • 63
  • 94
0
votes
1 answer

URL Encoding in swift converting space to %20 and then %20 to %2520

Here is the code struct URLParameterEncoder: ParameterEncoderProtocol { /// Takes dictionary parameters and encode them to make them safe to be passed as URLQueryItem in the URLRequest func encode(urlRequest: inout URLRequest, with…
Himan Dhawan
  • 864
  • 5
  • 19
0
votes
0 answers

Swift: Cannot get URL from URLComponents in Closure

I'm trying to create a url and store the string representation from within a closure. After accessing some JSON using URLSession, I create another url (using URLComponents) to be stored within an object in my model. However, my url keeps returning…
AUSTOOO
  • 41
  • 1
  • 9
1
2