Posts

Post not yet marked as solved
6 Replies
2.9k Views
I'm working on swift code that should create an instance of URLComponents. At one point the instance was successfully created. Now URLComponents always returns nil. I have tried two forms of URLComponents to create the instance.var urlComps: URLComponents = URLComponents()var urlComps: URLComponents = URLComponents(string: path)where path contains a valid url path. In both cases urlComps was nil.I created a new project and tried the code there and URLComponents returned nil instead of a new instance of the class.I put the URLComponents related lines of code in a playground and it worked fine. urlComps pointed to an instance of URLComponents.I'm using Xcode 11 and the swift 5 compiler built for iOS 13. I'm developing on a Macbook Pro running macOS 10.14.6, Mojave. Here is the code as it is currently written. public func get(path: String, queryParams: [String: String]) -> [String: String] { var response: [String: String] var urlComps: URLComponents = URLComponents() urlComps.path = "/user/auser" let URL = urlComps.url response = api(path: URL!, data: [:]) if(!response.isEmpty) { return response } else { return [:] } }
Posted Last updated
.