I have a menu which has an item for each value in an enum.
The menu:
[ ] Sort by Due Date
[ ] Sort by Priority
[√] Sort by Title
The enum:
typedef enum CW_TASK_SORT_METHOD {
CWTaskSortMethodDueDate,
CWTaskSortMethodPriority,
CWTaskSortMethodTitle
} CWTaskSortMethod;
The property:
@property(readwrite, assign) CWTaskSortMethod taskSortMethod;
What's the cleanest way to wire this up? I have two ideas but both strike me as unsatisfactory.
1st idea: Create properties for each value (sortMethodIsDueDate
, setSortMethodIsDueDate:
etc) These properties would call setTaskSortMethod:
and call valueDidChange:@"sortMethodIsDueDate"
etc. The menu items would then bind to these properties. This seems like a lot of work.
2nd idea: Connect each menu item to -(IBAction)updateSortMethod:(id)sender
which could then iterate the menu items and set the value depending on sender
. This approach is fine until taskSortMethod
is changed by a different section of code at which point code needs to be added to keep the menu in sync with taskSortMethod
.
I'm leaning towards the first approach as it has better separation between the V & C.
Any better ideas?