Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save harrysummers/d1470e0e9d8e45b4b45ec4b410822b24 to your computer and use it in GitHub Desktop.

Select an option

Save harrysummers/d1470e0e9d8e45b4b45ec4b410822b24 to your computer and use it in GitHub Desktop.
Getting album id from spotify link
extension String {
func getAlbumId() -> String? {
let url = self
let base = Constants.BASE_URL_NEW_ALBUM
let start = base.count
if url.contains(base) && url.count > start {
let startIndex = url.index(url.startIndex, offsetBy: start)
let substring = url[startIndex...]
var idString = ""
for letter in substring {
if letter == "?" {
return idString
} else {
idString.append(letter)
}
}
return nil
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment