iOS NSURL How to get last string component from URL (NSURL) in Swift

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Swift 2.3

let url = NSURL(string: "http://google.com/lastPath")
let lastPath = url?.lastPathComponent

Swift 3.0

  let url = URL(string: "http://google.com/lastPath")
  let lastPath = url?.lastPathComponent


Got any iOS Question?