|
I am trying to figure out a few things with this code. My ultimate goal is to make this a class file in my project to return a dictionary of playlists (or even better just modify in place a CoreData stored playlist dictionary in the future). I first retrieve the iTunes/Apple Music library and compare playlists to stored playlists within my app to check for any changes to the tracks in the playlist. If there are changes then I update the stored dictionary. As you can see below my structure is pretty simple - I use the name of a playlist as the key and the tracks of that playlist in the tracks dictionary as the value in the playlist dictionary. The tracks dictionary key is the persistendID of the song and the value is trackInfo. First problem: The library.musicfolderlocation is coming up 'nil' and I don't know why. I'm obviously getting into the library because I'm able to see the playlists and process them.
Second problem: Why are some the non-optional values in the trackInfo properties being stored as optionals, title being one of them (please see problem three output example)? How can I change the property value to be non-optionals for the properties that should not be optionals? I tried force-unwrapping but was told to not do that. Third problem: (problem two solution may resolve third problem) You'll notice when the code runs and prints the tracks[pid] property that it includes:
and the location: field is printing the Optional( also:
Fourth problem: I would like to validate that all required trackInfo properties have values assigned to them before I commit the trackInfo data to the tracks dictionary and then clear/empty/reset the trackInfo property after commiting the trackInfo to the tracks dictionary. Fifth problem: I takes approximately 10 seconds to process 46 playlists that have on average 68 tracks. Is there a more effecient way to do this? I'm new to Swift and I'm having one heck of a time understanding. This is a complicated language over others I have learned, but I'm excited to learn Swift and do some great things in the future. Here's the full code: (debugging print statements commented out to increase processing speed)
I appreciate any feedback. |
|
I used the exact code you supplied, just with all the First problem: This code works fine for me. Second problem: I don't see this issue either. The Third problem: I don't see this output, likely because the Fourth problem: Why clear/empty/reset the Fifth problem: I think that's down to your approach? Try something like the below, which takes a more functional approach to building your
|
|
Oh, and re: your note about
Although note that this property is deprecated and you should use |
|
Thank you. Your edits have enlighted me about Swift's list comprehension. Speed isn't any better on my system, but the code is much leaner. I see that the location URL is showing as:
However the actual location on disk is "/Volumes/Music-1/iTunes/iTunes Media/Music/Cliff Nobles & Co_/Single/01 The Horse.mp3" but if I try to use the URL to play the file using AVPlayer or similar this wouldn't play. This is why I need to figure out why the mediaFolderLocation (I changed it and it still doesn't work for me) is important. I can reconstruct the URL to the file if I could get that to work at least. I've read a lot about code signing plist items, etc. Just doesn't make sense to me that I can read the library but yet that property is showing as nil for me. Weird. As always, thanks for your help. |
|
Well, while I was looking for another playground I was using yesterday that did show the mediaFolderLocation I realized I was using a project on another computer via filesharing. I fired up the code locally and it was showing the correct full URL path. So, it must have something to do with remote libraries. Now I'm off to see the wizard... |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.