My solution for the challenge:


#1

First, here is the TL;DR version where the method I created is:

Here is the method in the BNRDocument.h file:

Here it is in the BNRDocument.m file:

[code]-(IBAction)deleteSelectedItem:(id)sender
{
if([todoItems count] != 0)
{

    NSInteger selectedRow = [itemTableView selectedRow];
    [todoItems removeObjectAtIndex:selectedRow];
    
    [itemTableView reloadData];
    [self updateChangeCount:NSChangeDone];
}

}[/code]

I also created a button in the BNRDocument.xib file and drug a connection from the new button, to the files owner and selected the “deleteSelectedItem” target.

Here is the full code if anyone wants it:

//BRNDocument.h

#import <Cocoa/Cocoa.h>

@interface BNRDocument : NSDocument
{
    NSMutableArray *todoItems;
    IBOutlet NSTableView *itemTableView;
}

-(IBAction)createNewItem: (id)sender;
-(IBAction)deleteSelectedItem:(id)sender;
@end
//BNRDocument.m
//
//  BNRDocument.m
//  TahDoodle
//
//  Created by Scott Nelson on 1/27/12.
//  Copyright (c) 2012 NA. All rights reserved.
//

#import "BNRDocument.h"

@implementation BNRDocument

- (id)init
{
    self = [super init];
    if (self) {
        // Add your subclass-specific initialization here.
        // If an error occurs here, return nil.
    }
    return self;
}

#pragma mark - NSDocument Overrides

- (NSString *)windowNibName
{
    // Override returning the nib file name of the document
    // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
    return @"BNRDocument";
}

- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];
    // Add any code here that needs to be executed once the windowController has loaded the document's window.
}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
    /*
     Insert code here to write your document to data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning nil.
     You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
     */
    /*NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil];
    @throw exception;
    return nil;*/
    
    //If there's no array, we'll write out an empty one for now
    
    if(!todoItems)
    {
        todoItems = [NSMutableArray array];
    }
    
    //Pack our todoItems array into an NSData object
    NSData *data = [NSPropertyListSerialization
                    dataWithPropertyList:todoItems format:NSPropertyListXMLFormat_v1_0 options:0 error];
    
    //return our newly-packed NSData object
    return data;
}

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
    /*
     Insert code here to read your document from the given data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning NO.
     You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
     */
   /* NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil];
    @throw exception;
    return YES;*/
    
    //Extract todoItems
    todoItems = [NSPropertyListSerialization
                 propertyListWithData:data options:NSPropertyListMutableContainers format:NULL error];
    
    //Return success or failure depending on success of the above call
    return (todoItems != nil);
}

#pragma mark - Actions
-(IBAction)createNewItem:(id)sender
{
    //If there is no array yet, create one to store task
    if(!todoItems)
    {
        todoItems = [NSMutableArray array];
    }
    
    [todoItems addObject:@"New Item"];
    
    //-reloadData tells the table view to refresh and ask its dataSource
    //(which happens to be this BNRDocument object in this case) for new data display
    [itemTableView reloadData];
    
    //-updateChangeCounttells the application whether or not the document
    //has unsaved changes. NSChangeDone flags the document as unsaved.
    [self updateChangeCount:NSChangeDone];
}

-(IBAction)deleteSelectedItem:(id)sender
{
    if([todoItems count] != 0)
    {
        
        NSInteger selectedRow = [itemTableView selectedRow];
        [todoItems removeObjectAtIndex:selectedRow];
        
        [itemTableView reloadData];
        [self updateChangeCount:NSChangeDone];
    }
}

#pragma mark Data Source Methods

-(NSInteger)numberOfRowsInTableView:(NSTableView *)tv
{
    //This table view is meant to display the todoItems
    //so the number of entries in the table view will be
    //the same as the number of objects in the array
    return [todoItems count];
}

-(id)tableView: (NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn 
           row:(NSInteger)row
{
    //Return the item from the todoItems that corresponds to the cell
    //that the table view wants to display
    return [todoItems objectAtIndex:row];
}

-(void)tableView:(NSTableView *)tableView 
  setObjectValue:(id)object 
  forTableColumn:(NSTableColumn *)tableColumn 
             row:(NSInteger)row
{
    //When the user changes a to-do item on the table view,
    //update the todoItems array
    [todoItems replaceObjectAtIndex:row withObject:object];
    
    //Flag the document as having unsaved changes
    [self updateChangeCount:NSChangeDone];
}

@end

EDIT: Oops I see there is two challenges, I didn’t do the second one yet :open_mouth: