Avoid staircasing by creating keyPath dynamically possible?
Hi all, This is part of XML parsing with NSXMLParser, is there any way to avoid this type of staircasing by constructing a keyPath dynamically? if (self.nestingLevel == 1) { [[[self.rootparser nodeTree] lastObject][@"items"] addObject:dict]; } if (self.nestingLevel == 2) { self.rootparser nodeTree] lastObject][@"items"] lastObject][@"items"] addObject:dict]; } if (self.nestingLevel == 3) { [self.rootparser nodeTree] lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] addObject:dict]; } if (self.nestingLevel == 4) { [[self.rootparser nodeTree] lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] addObject:dict]; } As you can see the action is always the same: addObject:dict But depending on the level of nesting, lastObject][@"items”] needs to be added multiple times to the self.rootparser’s nodeTree property. Is there any way to use a loop that runs for self.nestingLevel times and adds the extra levels to the keyPath just as many times as needed and then use that to access the noteTree at the exact right level? Although the above code works fine, I would much rather be able to use an abstract (variable) number of nesting levels, instead of the hardcoded 4 I am using now. Any thoughts would be appreciated, thanks! Best, Diederik ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Avoid staircasing by creating keyPath dynamically possible?
On Mar 7, 2015, at 5:02 AM, Diederik Meijer wrote: > This is part of XML parsing with NSXMLParser, is there any way to avoid this > type of staircasing by constructing a keyPath dynamically? > >if (self.nestingLevel == 1) { [[[self.rootparser nodeTree] > lastObject][@"items"] addObject:dict]; } >if (self.nestingLevel == 2) { self.rootparser nodeTree] > lastObject][@"items"] lastObject][@"items"] addObject:dict]; } >if (self.nestingLevel == 3) { [self.rootparser nodeTree] > lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] > addObject:dict]; } >if (self.nestingLevel == 4) { [[self.rootparser nodeTree] > lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] > lastObject][@"items"] addObject:dict]; } > > As you can see the action is always the same: addObject:dict > > But depending on the level of nesting, lastObject][@"items”] needs to be > added multiple times to the self.rootparser’s nodeTree property. > > Is there any way to use a loop that runs for self.nestingLevel times and adds > the extra levels to the keyPath just as many times as needed and then use > that to access the noteTree at the exact right level? No. Key paths can't index into arrays. However, you can just use a simply for loop. Something like: NSMutableArray* array = [[self.rootparser nodeTree] lastObject][@"items"]; for (int i = 1; i < self.nestingLevel; i++) array = array.lastObject[@"items"]; [array addObject:dict]; Regards, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Avoid staircasing by creating keyPath dynamically possible?
Thanks Ken, but this does not seem to traverse down into n nested levels, correct? The loop goes through the nodeTree's first level children only (pardon the bad semantics here) The aim is to add text sections to the appropriate items array, which can either be a chapter, a chapter's section or a chapter's section's subsection and so on... It is a multilevel table of contents This is why I need to expand the keyPath, so as to reach the appropriate nested level... But thanks for your thoughts, highly appreciated! Sent from my iPhone > On 07 Mar 2015, at 12:36, Ken Thomases wrote: > >> On Mar 7, 2015, at 5:02 AM, Diederik Meijer wrote: >> >> This is part of XML parsing with NSXMLParser, is there any way to avoid this >> type of staircasing by constructing a keyPath dynamically? >> >> if (self.nestingLevel == 1) { [[[self.rootparser nodeTree] >> lastObject][@"items"] addObject:dict]; } >> if (self.nestingLevel == 2) { self.rootparser nodeTree] >> lastObject][@"items"] lastObject][@"items"] addObject:dict]; } >> if (self.nestingLevel == 3) { [self.rootparser nodeTree] >> lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] >> addObject:dict]; } >> if (self.nestingLevel == 4) { [[self.rootparser nodeTree] >> lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] >> lastObject][@"items"] addObject:dict]; } >> >> As you can see the action is always the same: addObject:dict >> >> But depending on the level of nesting, lastObject][@"items”] needs to be >> added multiple times to the self.rootparser’s nodeTree property. >> >> Is there any way to use a loop that runs for self.nestingLevel times and >> adds the extra levels to the keyPath just as many times as needed and then >> use that to access the noteTree at the exact right level? > > No. Key paths can't index into arrays. However, you can just use a simply > for loop. Something like: > > NSMutableArray* array = [[self.rootparser nodeTree] lastObject][@"items"]; > for (int i = 1; i < self.nestingLevel; i++) >array = array.lastObject[@"items"]; > [array addObject:dict]; > > Regards, > Ken > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Avoid staircasing by creating keyPath dynamically possible?
On Mar 7, 2015, at 6:34 AM, Diederik Meijer wrote: >> On 07 Mar 2015, at 12:36, Ken Thomases wrote: >> >>> On Mar 7, 2015, at 5:02 AM, Diederik Meijer wrote: >>> >>> This is part of XML parsing with NSXMLParser, is there any way to avoid >>> this type of staircasing by constructing a keyPath dynamically? >>> >>> if (self.nestingLevel == 1) { [[[self.rootparser nodeTree] >>> lastObject][@"items"] addObject:dict]; } >>> if (self.nestingLevel == 2) { self.rootparser nodeTree] >>> lastObject][@"items"] lastObject][@"items"] addObject:dict]; } >>> if (self.nestingLevel == 3) { [self.rootparser nodeTree] >>> lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] >>> addObject:dict]; } >>> if (self.nestingLevel == 4) { [[self.rootparser nodeTree] >>> lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] >>> lastObject][@"items"] addObject:dict]; } >>> >>> As you can see the action is always the same: addObject:dict >>> >>> But depending on the level of nesting, lastObject][@"items”] needs to be >>> added multiple times to the self.rootparser’s nodeTree property. >>> >>> Is there any way to use a loop that runs for self.nestingLevel times and >>> adds the extra levels to the keyPath just as many times as needed and then >>> use that to access the noteTree at the exact right level? >> >> No. Key paths can't index into arrays. However, you can just use a simply >> for loop. Something like: >> >> NSMutableArray* array = [[self.rootparser nodeTree] lastObject][@"items"]; >> for (int i = 1; i < self.nestingLevel; i++) >> array = array.lastObject[@"items"]; >> [array addObject:dict]; > > > Thanks Ken, but this does not seem to traverse down into n nested levels, > correct? It does traverse down. It's just like your code, except generalized. > The loop goes through the nodeTree's first level children only (pardon the > bad semantics here) Each time through the loop, it reassigns the "array" variable. So, the next time through the loop, it's accessing a deeper level of the tree. Regards, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Avoid staircasing by creating keyPath dynamically possible?
Sorry, yes I see now!! Will try that out and let you know! Sent from my iPhone > On 07 Mar 2015, at 13:43, Ken Thomases wrote: > > On Mar 7, 2015, at 6:34 AM, Diederik Meijer wrote: > >>> On 07 Mar 2015, at 12:36, Ken Thomases wrote: >>> On Mar 7, 2015, at 5:02 AM, Diederik Meijer wrote: This is part of XML parsing with NSXMLParser, is there any way to avoid this type of staircasing by constructing a keyPath dynamically? if (self.nestingLevel == 1) { [[[self.rootparser nodeTree] lastObject][@"items"] addObject:dict]; } if (self.nestingLevel == 2) { self.rootparser nodeTree] lastObject][@"items"] lastObject][@"items"] addObject:dict]; } if (self.nestingLevel == 3) { [self.rootparser nodeTree] lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] addObject:dict]; } if (self.nestingLevel == 4) { [[self.rootparser nodeTree] lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] lastObject][@"items"] addObject:dict]; } As you can see the action is always the same: addObject:dict But depending on the level of nesting, lastObject][@"items”] needs to be added multiple times to the self.rootparser’s nodeTree property. Is there any way to use a loop that runs for self.nestingLevel times and adds the extra levels to the keyPath just as many times as needed and then use that to access the noteTree at the exact right level? >>> >>> No. Key paths can't index into arrays. However, you can just use a simply >>> for loop. Something like: >>> >>> NSMutableArray* array = [[self.rootparser nodeTree] lastObject][@"items"]; >>> for (int i = 1; i < self.nestingLevel; i++) >>> array = array.lastObject[@"items"]; >>> [array addObject:dict]; > >> >> Thanks Ken, but this does not seem to traverse down into n nested levels, >> correct? > > It does traverse down. It's just like your code, except generalized. > >> The loop goes through the nodeTree's first level children only (pardon the >> bad semantics here) > > Each time through the loop, it reassigns the "array" variable. So, the next > time through the loop, it's accessing a deeper level of the tree. > > Regards, > Ken > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
disabling Apple Crash Reporter
Is there a way to disabled the Apple crash reporter dialog? I want to use PLCrashReporter and show my UI instead. I don't want to confuse the user by having to fill out two crash reports. So far I only found a ways to turn if off completely: sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.locate.plist defaults write com.apple.CrashReporter DialogType none And in the docs I found a reference to a CrashReporterPrefs.app but that information seems to be outdated. Is there a way to just disable it for my app? cheers, Torsten ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSBrowser Frustration
Now I feel stupid. For efficiency, my code was caching the values for the second column, but I never cleared that cache before trying to refresh that column. The browser was refreshing the (now incorrect) cached values - clearing my cache out so that it was rebuilt fixed my issue. Sorry for any confusion! On 3/7/2015 12:39, Frank D. Engel, Jr. wrote: I have an NSBrowser class which has at most two columns; it is populated from a core data store. If I delete an object from the core data store that is from the first column of the browser, I can send loadColumnZero to the browser object, and it correctly refreshes the column and deselects everything. I cannot, however, find a programmatic way to correctly refresh the second column (column number 1) when I delete something from there. If I try loadColumnZero, then reselect the item in the first column, the second column shows a blank entry in the second column where the old object was. If I select a different item in the first column, then reselect the one that would show the deleted item, then it refreshes correctly; but if I programmatically do this within the method that performs the delete, it ends up showing the same thing as if I hadn't done the reload. I have tried reloadColumn:1, reloadDataForRowIndexes..., and numerous combinations of these and other method calls, and no matter what I try I can't seem to get it to just refresh the column. The only thing that comes close to doing what I want is to have it select a different item in the first column (selectRow:0 inColumn:0), which leaves it on the "wrong" item in the first column - when I then manually select the desired column, it does correctly reload. What am I missing - how can I get it to just do the sensible thing and refresh the data in the second column? This is getting frustrating, and I'm sure I must be missing something simple...? I'm on OS X 10.9.5 if that makes a difference. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com