Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, let's back up and look at what you REALLY have. You already have all the information that you need residing in songs. Why are you in essence duplicating it merely to break out the artist?</p> <p>Think of it this way, if you have the following songs (song/artist)</p> <pre><code>(0) "Death Eater", "Raging Machine Code" (1) "Interrupt", "Raging Machine Code" (2) "Panic", "Times Square Revolution" (3) "New Years", "Times Square Revolution" (4) "Toast", "Ed &amp; Billy's Time Machine" (5) "Surge", "Quiet Cat" (6) "Surveil", "Quiet Cat" </code></pre> <p>What is wrong with this picture? We have the same information duplicated. Ideally, we want to have something like this:</p> <pre><code>"Raging Machine Code" -&gt; has an array that contains "Death Eater" "Interrupt" "Times Square Revolution" -&gt; has an array that contains "Panic" "New Years" "Ed &amp; Billy's Time Machine" -&gt; array that contains "Toast" "Quiet Cat" -&gt; array that contains "Surge" "Surveil" </code></pre> <p>For UITableView this makes things trivial - we tell it how many sections (four) and for each section how many songs. To generate the cell, we get an NSIndexPath that tells us the section and the row (section would be the artist and the row would be the song for that artist).</p> <p>NSTableView doesn't do that. It gives us a row. However, if we do some work on the front end (i.e. the song list) then we can assure that life will be beautiful and fast (or at least faster). The key is to pre-calculate the number of songs per artist and store it.</p> <p>So assume we are asked to display row 5. "Raging Machine Code" is 0-2 (artist, song, song). "Times Square Revolution" is 3-5. Ah! 5 is the last song, so we display "New Years"!</p> <p>Try another one, assume we are to display row 6. "Raging..." was 0-2, "Times..." was 3-5, "Ed &amp; Billy's" is 6-7. Bingo, we need to display the artist, "Ed &amp; Billy's Time Machine"!</p> <p>The idea is that we do much of this prework AHEAD of actually displaying the data. Looping through artists will be far faster than looping through ALL the songs. Plus now you are only doing simple math - no need to move things.</p> <p>Sometimes how you store your data means the difference between success and failure. Whenever you see yourself having to "redefine a data structure" that usually means your data structure is faulty - it may be simple, but it causes more effort.</p> <p>Hopefully this was helpful and didn't end up being "TLTR" (too long to read).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload