Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Displaying Data with Table Views in Swift 2 Enhancing the Networking Stack Enhancing the Endpoint Protocol

Kevin Gutowski
Kevin Gutowski
4,082 Points

Difference between NSURL and URL?

Confused about the differences between NSURL and URL (likewise NSURLQueryItem and URLQueryItem, etc). When should I use one over the other?

It has to do with what version of Swift you are using. Swift 3 has created reference types to several structures in foundation, one of them is URL based structs and classes. They are identical in usage, Apple has chosen to drop the NeXTSTEP prefix in support of using foundation with Swift on multiple platforms like iOS, Android, and Linux.

    public typealias ReferenceType = NSURL

from Apple:

"The Swift overlay to the Foundation framework provides the URL structure, which bridges to the NSURL class. The URL value type offers the same functionality as the NSURL reference type, and the two can be used interchangeably in Swift code that interacts with Objective-C APIs. This behavior is similar to how Swift bridges standard string, numeric, and collection types to their corresponding Foundation classes."

[API Reference](https://developer.apple.com/reference/foundation/nsurl/