Concatenating a SoundCloud Playlist Update JSON
You can make this easier with mapping.  

So, let's clarify what we have.


playlist.tracks - An array of "tracks" which have an id property (which is what we need).
trackID - an integer representing our new track
myTracks - an array of dictionaries in the form of key "id" and value being the track ID.
myParams - a dictionary with the key of "tracks" and the value being the aforementioned myTracks array.


So we need to turn playlist.tracks into an array of ["id":id] dictionaries with the new track ID also in there.

First, let's ignore the new track, and map the existing tracks into an array of dictionaries:

var trackIDdicts: [[String:Int]] = playlist.tracks.map { ["id":$0.id] }


And now insert our new track ID at the front:

trackIDdicts.insert(["id":trackId], atIndex:0)


And now for myParams?

myParams["playlist"] = ["tracks":trackIDdicts]




Altogether, three simple lines of code:

var trackIDdicts: [[String:Int]] = playlist.tracks.map { ["id":$0.id] }
trackIDdicts.insert(["id":trackId], atIndex:0)
myParams["playlist"] = ["tracks":trackIDdicts]




I'd highly recommend converting your JSON/Dictionary keys into named constant variables however.

struct JSONKeys {
    static let TrackID = "id"
    static let Tracks = "tracks"
    static let Playlist = "playlist"   
}


So now we have:

var trackIDdicts: [[String:Int]] = playlist.tracks.map { [JSONKeys.TrackID:$0.id] }
trackIDdicts.insert([JSONKeys.TrackID:trackId], atIndex:0)
myParams[JSONKeys.Playlist] = [JSONKeys.Tracks:trackIDdicts]