7

I'm getting the titleForHeaderInSection correctly, where its pulling the leaf.

But getting nothing for themes.

I'm guessing my mapping to themes is not working, because cellForRowForIndexPath doesn't seem to be getting called when I set breakpoints.

But obviously I'm not sure and thats why I'm looking for some guidance. Thanks!

API JSON

{
    "springs": [{
        "name": "baskets",
        "leafs": [{
            "name": "New Season",
            "abbreviation": "nb",
            "themes": [{
                "name": "Hops",
                "abbreviation": "HS",
}          

ViewController.h

@property (strong, nonatomic) NSArray *springs;
@property (strong, nonatomic) NSMutableArray *leafs;
@property (strong, nonatomic) NSMutableArray *themes;
Realinstomp
  • 532
  • 2
  • 13
  • 30
  • Turn on trace logging as the first thing you do, not after you have started the load – Wain Apr 26 '14 at 20:21
  • Moved the code per your advice. Is that what you were talking about, and is that ALL that you were talking about, or is there anything else needed on that front? Thanks Wain! – Realinstomp Apr 27 '14 at 22:03

1 Answers1

5

This line

  [springMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"themes" toKeyPath:@"themes" withMapping:themeMapping]];

Should be

  [leafMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"themes" toKeyPath:@"themes" withMapping:themeMapping]];

Because the theme is nested inside leaf (which is itself nested inside spring).

Wain
  • 118,658
  • 15
  • 128
  • 151
  • That makes perfect sense! I'm still not getting it to work, do you see any other problems with my code? Thanks for the help, seriously. – Realinstomp Apr 14 '14 at 23:46
  • If there's any additional info you need from me to help too, just let me know – Realinstomp Apr 14 '14 at 23:46
  • Turn on trace logging and post that here. What specifically isn't working (did it change when you fixed the relationship)? – Wain Apr 15 '14 at 07:34
  • I'm trying to google "trace logging" and not finding it really. Can you be more specific for me what it is called in Xcode or what tool I should be using in there? For now, what I'm doing to debug this is breakpoints & the console – Realinstomp Apr 15 '14 at 22:59
  • I'm setting a breakpoint at every line of the `cellForRowAtIndexPath`. When I do that and run the application, its hits the first breakpoint on the method name, and hops two lines down to `UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]`... that line becomes highlighted. – Realinstomp Apr 15 '14 at 23:03
  • Then I step forward, it goes to `Spring *springLocal = [springs objectAtIndex:0];', and the console shows 1 object for `springs` - `_NSArrayM`, which makes sense. If I open up the other disclosure arrows, it shows 1 object for `_leafs` which is correct, and the corresponding abbreviation (which is the abbreviation I used in the `titleForHeaderInSection` method. – Realinstomp Apr 15 '14 at 23:05
  • However, in that same part under `_leafs`, it shows `themes = (NSArray *)nil`... and `themes` stays `nil` as I step thru all the way to `cell.textLabel.text = theme.name;`... at which point once I step thru that it pops the Simulator into the forefront with the `tableView` cells blank. Any ideas? – Realinstomp Apr 15 '14 at 23:09
  • http://stackoverflow.com/questions/10336259/iphone-restkit-how-to-enable-rklogdebug – Wain Apr 16 '14 at 07:18
  • So I put `RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);`... nothing sticks out to me to look for. I don't see `themes` coming up anywhere in that specific log. I only see it in the JSON that I'm pulling from. Should I use a different RKLog? – Realinstomp Apr 17 '14 at 00:41
  • 1. T restkit.object_mapping:RKMapperOperation.m:321 Examining keyPath 'springs' for mappable content... 2. Performing mapping operation: for 'Spring' object. Mapping values from object { 3. Found transformable value at keyPath 'name'. Transforming from class '__NSCFString' to 'NSString' 4. Mapping attribute value keyPath 'name' to 'name' 5. Mapped attribute value from keyPath 'name' to 'name'. Value: basket 6. Performing nested object mapping using mapping leafs> for data: { – Realinstomp Apr 17 '14 at 00:47
  • 7. Performing mapping operation: for 'Leaf' object. Mapping values from object { 8. Found transformable value at keyPath 'abbreviation'. Transforming from class '__NSCFString' to 'NSString' 9. Mapping attribute value keyPath 'abbreviation' to 'abbreviation' 10. Mapped attribute value from keyPath 'abbreviation' to 'abbreviation'. Value: na 11. Found transformable value at keyPath 'leafs'. Transforming from class '__NSArrayM' to 'NSMutableArray' 12. Mapped relationship object from keyPath 'leafs' to 'leafs'. Value: ( "" ) – Realinstomp Apr 17 '14 at 00:48
  • Will it help if I log something different? I might not know what your looking for since I'm newer to trace logging. Thanks! – Realinstomp Apr 17 '14 at 00:51
  • I'm not getting any errors since I changed the addPropertyMapping, so thats good. But its also not mapping to `themes` for some reason still. – Realinstomp Apr 17 '14 at 01:08
  • Add your updated code to the question and upload the trace log somewhere and provide a link to it – Wain Apr 17 '14 at 07:23
  • Updated my code to reflect changes in mapping, tableview, and logging. – Realinstomp Apr 17 '14 at 22:02
  • See anything that stands out as the culprit? – Realinstomp Apr 17 '14 at 23:21
  • Need me to post any extra code to help out? What do ya think? Thanks Wain! – Realinstomp Apr 19 '14 at 15:05
  • Is that the full trace log after it logs the post request being sent? Code looks good... – Wain Apr 22 '14 at 07:28
  • That (the gist) is the full trace log from my console per the code in my `viewController`. Is that what you were asking? – Realinstomp Apr 22 '14 at 22:27
  • Yes, it just doesn't show as much as I expect. The code looks to match the JSON well. The log seems to start too late and doesn't even attempt themes. Need to debug the mapping operation... – Wain Apr 23 '14 at 07:33
  • How would I go about debugging the mapping operation differently than what I did with the trace log? Thanks! – Realinstomp Apr 23 '14 at 22:26
  • Breakpoints, what does it do when it finds the theme key, why doesn't it process it? – Wain Apr 23 '14 at 22:48
  • 1.) Hits `numberOfSectionsInTableView`, then step forward 2.) Hits `titleForHeaderInSection`, step forward 3.) Hits `numberOfRowsInSection`, then step forward 4.) Loads the blank `viewController` on screen, then step forward 5.) `numberOfSectionsInTableView`, then step forward 6.) `titleForHeaderInSection`, then step forward 7.) `numberOfRowsInSection`, then step forward 8.) `titleForHeaderInSection`, step forward 9.) Done with sequence, shows viewController on screen with correct `leaf` text in the title, but no `themes` in the cells – Realinstomp Apr 24 '14 at 23:57
  • Pretty funky, see some problems in there? Thanks Wain!! – Realinstomp Apr 24 '14 at 23:58
  • I was thinking more debugging RKMappingOperation.m around line 438 to see why it processes leafs but not themes – Wain Apr 25 '14 at 07:23
  • I see line 438, but I'm not clear exactly how to do what your saying with debugging that file, can you give me a little guidance? Trying to figure it out but not making any headway. – Realinstomp Apr 26 '14 at 02:18
  • I put a breakpoint at that line, but am not sure what I should be looking for because its not really showing me any themes info, so I'm not sure whats missing exactly that I should be looking for. – Realinstomp Apr 26 '14 at 02:21
  • Upgrade to version 0.23.1 as line 438 doesn't exist now. We're looking at what the mapping contains and the data being processed. Your JSON and spec both have themes so looking at what is causing it not to be processed. – Wain Apr 26 '14 at 08:54
  • Just upgraded to version 0.23.1. I'm with you on what we are looking for, and that themes is not showing up, but I'm still trying to figure out specifically what to do to debug. I already have `RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);` in my `viewDidLoad`. I've set breakpoints basically on every line of the tableView information. What else specifically are you saying to do, and how specifically are you saying to implement it? – Realinstomp Apr 27 '14 at 21:11
  • A lot of times when I'm trying to figure out new ways of trying to do this, `cellForRowAtIndexPath` isn't even getting called. Obviously it relates to our problem here, because in `numberOfRowsInSection` try's to return `leafLocal.themes.count;` and that must obviously be returning 0 because its counting 0 `themes`. – Realinstomp Apr 27 '14 at 21:21
  • In the console when I'm debugging w breakpoints it definitely has `springLocal` that has a `_leafs = (NSArrayM *)@"1 object".` Whereas, `leafLocal` has `_themes = (NSMutableArray *)nil` – Realinstomp Apr 27 '14 at 21:55
  • The table view comes well after the mapping so break points there won't help. Trace log needs to be turned on before doing any other code. When the mapping operation is processing leafs it should have nested themes and a relationship on the mapping for themes, this is the first thing we're trying to verify (then why is it missing / not working). Start in the `applyNestedMappings` method in the mapping operation. – Wain Apr 28 '14 at 07:18
  • Cool I will try this today. In the meantime I'm gonna give you the bounty too. – Realinstomp Apr 28 '14 at 17:49
  • I updated the `viewDidLoad` in my question to reflect moving the trace log per your comment. Is that what you mean by turning it "on" (on = pasting that line of code at the beginning of `viewDidLoad`)? Or is there an extra step I'm missing? – Realinstomp Apr 29 '14 at 02:31
  • Also, what should I do once I'm in the `Code/ObjectMapping/RKMappingOperation.m` and have found the `applyNestedMappings`? Am I setting breakpoints there or something? Or am I doing something else/more? – Realinstomp Apr 29 '14 at 02:32
  • Correct, beginning of the method. Yes, breakpoint and examine the data, looking for the data being processed (spring / leaf / theme) and the mappings being applied - is the data wrong or the mapping wrong (localise the problem) – Wain Apr 29 '14 at 08:13
  • Above in my answer I added 2 screenshots to be helpful, since I can't copy and past any code from that console log. – Realinstomp May 01 '14 at 00:49
  • And then added 4 more screenshots right now to help even more – Realinstomp May 01 '14 at 00:56
  • Basically, its showing leagues (leagues = leafs, I just switched the words for posting to Stack) as an array inside of the `mutableMapping`, perfectly corresponding with the Spring.h file's 2 properties. – Realinstomp May 01 '14 at 01:02
  • But when I step forward, its not showing themes as an array inside of `mutableMapping`, when it should be showing the 4 properties (not just 3) in Leaf.h – Realinstomp May 01 '14 at 01:04
  • I guess I'm not sure where to keep looking from here, let me know what you think? Its obviously not mapping `themes`, but I'm still trying to figure out why. – Realinstomp May 01 '14 at 01:05
  • When you create the mapping initially, and the response descriptor, breakpoint there and examine the mappings in the same way. As you see the relationship in the first mapping you should see another in the second. Is `themeMapping` not being instantiated somehow? I'd expect that to throws errors... – Wain May 01 '14 at 07:21
  • Yeah I was trying that and what stood out at me, even though I can't quite figure out why its like this is, in the console, `leafMapping` looks a bit different than `springMapping` and `themeMapping`, do you know why its doing `UIViewController` instead of `RKMapping`? (Added picture of what I'm talking about above) – Realinstomp May 02 '14 at 00:26
  • (I separated all of the additions in my Question, to be helpful, you will find them under todays date 5/1/14). Thanks Wain! – Realinstomp May 02 '14 at 00:50
  • The debugger is likely lying there (it does sometimes), log to get the truth. The code in the question, how different is it from your real code? I can't see a reason for the nested mapping to not be applied. It's all about the mappings and the mapping operation (based on the trace log), by the time you get to the table things have already gone wrong. – Wain May 02 '14 at 07:51
  • I can't see an issue with the code (it basically runs recursively and the configuration is the same for the mapping that works and the one that doesn't). The mapping log in the debugger initially looks ok, but then is broken / messy. The trace log basically says the teams mapping doesn't exist. It remains a debugging issue to determine what happens to the mapping. I can't suggest anything else I'm afraid (other than cleaning the project and using a minimal JSON example to make the debugging easier). – Wain May 03 '14 at 08:36
  • Gotcha. "Using a minimal JSON example to make the debugging easier" = pulling different JSON so there's not as much to work thru? – Realinstomp May 03 '14 at 12:50
  • I'm just trying to update from 0.10 to 0.20, so this kinda stinks I can't figure it out ha – Realinstomp May 03 '14 at 13:04
  • Yes, a single sport, with one league and one team each containing only the keys that you want to map would be ideal, so each mapping should only be applied once and contain only pertinent information – Wain May 03 '14 at 14:05
  • Are you able to upload the project somewhere so I can take a look at the whole thing (with small JSON sample / request)? – Wain May 05 '14 at 07:08
  • Yes absolutely. Is a Dropbox link or GitHub link better? And do you have a way I can message/email it to you? – Realinstomp May 05 '14 at 23:06
  • Either. Can't guarantee when I have time to look at it and you would need to put the link here... – Wain May 06 '14 at 07:33
  • The problem is nothing to do with the mapping. You are configuring multiple object managers and only ever using the first one (`[RKObjectManager sharedManager]`). Either use one manager or keep each in a property and use the correct one. – Wain May 07 '14 at 07:54
  • Gotcha. Where am I configuring multiple object managers... I don't have a `RKObjectManager` property set up or anything? – Realinstomp May 08 '14 at 00:05
  • Cant look at it right now. You don't have a property, but each view controller is creating a new object manager for itself. So each should have a property and you should never use `sharedManager`. – Wain May 08 '14 at 10:00
  • (Also, I'm gonna give you the new 100 point bounty right now since you've been so helpful along the way) – Realinstomp May 11 '14 at 23:32
  • Hi is the issue with not being able to load the teams. – Sandeep May 11 '14 at 23:35
  • I have solved it . Shall I push the code to github. I have very little changes. – Sandeep May 11 '14 at 23:37
  • You have this line `teamsManager = self.teamsObjectManager;` the wrong way round. You should be assigning the new instance to the instance property. Currently you assign the empty instance property to the instance variable and thus the instance gets destroyed... – Wain May 12 '14 at 17:48
  • You save `teamsESPN = mappingResult.array;` but then don't use `teamsESPN` in your table view methods... – Wain May 13 '14 at 23:29
  • HOOOOOOOOOOOOLY CRAP, THANK YOU!!!! I finally see it working now. Man, you seriously are the best ever. – Realinstomp May 13 '14 at 23:35