Search code examples
iosdictionarysirishortcuts

Adding Items from Lists to Dictionaries in Apple Shortcuts


I have this Shortcut which queries a Notion database, then fetches the IDs and titles of pages from the database and turns them into key : value pairs.

shortcut

I want to add those key : value pairs to the dictionary shown at the top of the screenshot. The problem is, even though I can see that I'm adding to the dictionary inside the Repeat With Each Item loop -

alert screenshot

When I check the contents of my Categories dictionary at the end of the Shortcut, those entries haven't been saved.

I have seen this answer, which appears to solve the same problem. But when I implement it and then check the contents of the variable inside the loop, nothing is even being set here.

setting variables screenshot

I'd be very grateful for any pointers here.


Solution

  • I figured out the problem - I needed to set the dictionary as a variable outside the loop -

    categories dictionary

    And then I can update the dictionary inside the loop -

    enter image description here

    I don't know why that works but it does ¯\(ツ)