Created
May 12, 2018 21:44
-
-
Save harrysummers/d1470e0e9d8e45b4b45ec4b410822b24 to your computer and use it in GitHub Desktop.
Getting album id from spotify link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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