I am an iOS Developer and have developed several apps for iPhone so I decided to create a Mac App for fun and to open source it for others to learn.
Compared to iOS, there are very few examples and tutorials online teaching you how to write apps for Mac so I decided to make a simple Todo list app. The App is simple in that it allows users to enter todos to their list and check it when its complete.
For the App I decided to use the principles I learned on iOS of using a table view where each table view cell contains a checkbox and textfield.
One thing I found different right away was that the table view in Mac Apps contained columns which is different from UITableView which only contains rows of UITableViewCell. Hence the datasource method signature is different in Mac where this method is called to get a NSView for a given row and column.
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
Another thing I found difficult was the ability to rearrange rows in the NSTableView. First I searched on Google and Stackoverflow for some tutorials or sample code but there are very few projects and examples.
In iOS you just have to implement these two methods with relatively little code to get the rearranging functionality out of box.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
In Mac you have to implement these three methods and write a lot of logic code to handle the rearranging of the table view rows
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pasteboard
I was not very impressed by this as the logic code to rearrange that could be written in iOS in just 4 lines of code is now 40 lines in Mac. I would imagine that Apple by now would have spent time to make some of the common use cases like these along with deleting a row item easier for developers to implement just like iOS.
What drew me to iOS was the ability to write less code especially when sticking with Apple’s user interaction guidelines and design patterns but I would not say the same for Mac App development.
The Todo list app source code is posted on Github if anyone is interested in reading the source code or enhancing the app by forking it: https://github.com/ankurp/Todo-List-for-Mac-OS-X