2 // NSMenu+RepresentedObjectAccessors.m
5 // Created by Joe Wreschnig on 3/4/13.
9 #import "NSMenu+RepresentedObjectAccessors.h"
11 @implementation NSMenu (RepresentedObjectAccessors)
13 - (NSMenuItem *)itemWithRepresentedObject:(id)object {
14 for (NSMenuItem *item in self.itemArray)
15 if ([item.representedObject isEqual:object])
20 - (void)removeItemWithRepresentedObject:(id)object {
21 NSInteger idx = [self indexOfItemWithRepresentedObject:object];
23 [self removeItemAtIndex:idx];
26 - (NSMenuItem *)lastItem {
27 return self.itemArray.lastObject;
30 - (void)removeLastItem {
31 if (self.numberOfItems)
32 [self removeItemAtIndex:self.numberOfItems - 1];
37 @implementation NSPopUpButton (RepresentedObjectAccessors)
39 - (NSMenuItem *)itemWithRepresentedObject:(id)object {
40 return [self.menu itemWithRepresentedObject:object];
43 - (void)selectItemWithRepresentedObject:(id)object {
44 [self selectItemAtIndex:[self indexOfItemWithRepresentedObject:object]];