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.

28 questions
88
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
  • 931
  • 1
  • 6
  • 9
50
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
  • 76,236
  • 42
  • 207
  • 306
9
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
  • 37,241
  • 25
  • 195
  • 267
3
votes
1 answer

Swift Components.Url is Returning the Wrong URL

I implemented the following code, where I can pass in the name of the resource and it should give me the URL. I am using Xcode 14 Beta 3. static let baseUrl = "localhost:8080" static func resource(for resourceName: String) -> URL? { …
Mary Doe
  • 1,073
  • 1
  • 6
  • 22
2
votes
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
  • 6,934
  • 17
  • 74
  • 134
2
votes
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
  • 77
  • 1
  • 10
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
  • 2,901
  • 4
  • 22
  • 37
2
votes
2 answers

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
  • 15,493
  • 31
  • 131
  • 244
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
  • 12,320
  • 3
  • 50
  • 63
1
vote
0 answers

What's the difference between custom url schemes that have two forward slashes vs those that do not?

I’m looking at supporting a custom url scheme in my app. Apple’s documentation notes this format without two forward slashes after the colon: myphotoapp:Vacation?index=1 URL schemes I've seen previously use :// not just : for example…
Jordan H
  • 52,571
  • 37
  • 201
  • 351
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
  • 128
  • 7
1
vote
2 answers

How to prevent URLComponents().port from adding a question mark before the query (Swift/Xcode)

I am trying to compose a representative URLComponents() in the app I am designing. Here is the code: class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var components = URLComponents() …
mansanto
  • 360
  • 4
  • 16
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"]…
Abhijit Hadkar
  • 210
  • 2
  • 11
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…
Aaban Tariq Murtaza
  • 1,155
  • 14
  • 16
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…
0xChqrles
  • 433
  • 1
  • 5
  • 10
1
2