I'm confused. You posted data from the middle of a plist. It shows an entry, item 2, from the middle of an array. It isn't clear what is the outermost object in that plist.
Then you posted code that's reading data from NSUserDefaults, with a key of "InfoArray". Is what you posted one entry from the "InfoArray" structure you're reading from user defaults?
Your code never reads the "exercises" key from the outermost dictionary array entry 2, so I don't understand how the first block of code works.
The second block of code is written as if the same dictionary that contains the "exerciseName" key also contains a "muscleName" key, but it does not. From the little image you posted, I can't tell for sure what the structure of your file is. It looks like the outermost dictionary contains the key/value "exercises" and the key/value "muscleName". Thus, you need to fetch the "muscleName" key/value from the same dictionary you used to read your "exercises" key/value pair. But, as I said,you did not show how you're reading the "exercises" key/value.
You need to show us a more complete picture of what's going on.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I'm confused. You posted data from the middle of a plist. It shows an entry, item 2, from the middle of an array. It isn't clear what is the outermost object in that plist.
Then you posted code that's reading data from NSUserDefaults, with a key of "InfoArray". Is what you posted one entry from the "InfoArray" structure you're reading from user defaults?
Your code never reads the "exercises" key from the outermost dictionary array entry 2, so I don't understand how the first block of code works.
The second block of code is written as if the same dictionary that contains the "exerciseName" key also contains a "muscleName" key, but it does not. From the little image you posted, I can't tell for sure what the structure of your file is. It looks like the outermost dictionary contains the key/value "exercises" and the key/value "muscleName". Thus, you need to fetch the "muscleName" key/value from the same dictionary you used to read your "exercises" key/value pair. But, as I said,you did not show how you're reading the "exercises" key/value.
You need to show us a more complete picture of what's going on.
Thanks,
Here is a full picture that should show the structure of the .plist
Both methods I had are loading data from the same plist. I used the first method to successfully update a label with exercise name. I also used the second method to successfully create muscleArray elsewhere to load a tableView.
What I need to do is use that muscleArray and load the label with the muscleName depending on what muscle from the tableView was selected.
Here is a full picture that should show the structure of the .plist
Both methods I had are loading data from the same plist. I used the first method to successfully update a label with exercise name. I also used the second method to successfully create muscleArray elsewhere to load a tableView.
What I need to do is use that muscleArray and load the label with the muscleName depending on what muscle from the tableView was selected.
To repeat:
The second block of code is written as if the same dictionary that contains the "exerciseName" key also contains a "muscleName" key, but it does not.
The first code you posted that reads "exerciseName" gets an object from an array, and assumes it's a dictionary. It then looks for the key "exerciseName" in that dictionary.
Your second block of code tries to read another key "muscleName" from the same dictionary. There is no key "muscleName" in that dictionary. Instead, "muscleName" is is a key in a parent dictionary. That's why it doesn't work. You need to look at your data carefully, and pay attention to the grouping of your objects. Either the data is not structured correctly, or your code is not written to read the structure correctly. I don't have a clear enough understanding to tell which. It's up to you to figure it out.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
The second block of code is written as if the same dictionary that contains the "exerciseName" key also contains a "muscleName" key, but it does not.
The first code you posted that reads "exerciseName" gets an object from an array, and assumes it's a dictionary. It then looks for the key "exerciseName" in that dictionary.
Your second block of code tries to read another key "muscleName" from the same dictionary. There is no key "muscleName" in that dictionary. Instead, "muscleName" is is a key in a parent dictionary. That's why it doesn't work. You need to look at your data carefully, and pay attention to the grouping of your objects. Either the data is not structured correctly, or your code is not written to read the structure correctly. I don't have a clear enough understanding to tell which. It's up to you to figure it out.
Thanks Duncan.
So my data is structured correctly, but my code is not written to read the structure correctly. So how can I edit the method to reflect this?
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.