Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 4, 2011, 04:42 AM   #1
Monaj
macrumors regular
 
Join Date: May 2009
Efficiently implementing simple NSComboBox functionality with bindings

I made a sample core data application, in which I populated NSComboBox with name of Student entity, by binding its content values property to an array controller. I wanted to add new record to persistent store if student name does not exist, so I defined this method in application delegate class:

Code:
- (IBAction)addNewStudent:(id)sender
    {
        NSArray *studentNames = [[students arrangedObjects] valueForKey:@"name"];
        if ([studentNames containsObject:[sender stringValue]]) {
            return;
        }
        
        NSManagedObjectContext *context = [self managedObjectContext];
        NSEntityDescription *studentEntity = [NSEntityDescription entityForName:@"Student" inManagedObjectContext:context]; 
        
        // inserting record
        NSManagedObject *newRecord = [NSEntityDescription insertNewObjectForEntityForName:[studentEntity name] inManagedObjectContext:context];
        [newRecord setValue:[sender stringValue] forKey:@"name"];
        
        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Unresolved error %@, %@",error,[error userInfo]);
            abort();
        }
    }
Can anyone suggest me, if it is the best way to implement it or there is any other better approach to implement it?

Last edited by Monaj; Jul 4, 2011 at 06:49 AM.
Monaj is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
bindings, cocoa, nsarraycontroller, nscombobox

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Efficiently installing the new Mac Pro toto2007 Mac Pro 6 Feb 26, 2014 12:34 AM
How to transfer files efficiently between Macs? aznboi91 iMac 16 Nov 5, 2013 01:47 AM
How to take photos on iphone efficiently djsound iPhone 21 May 24, 2013 02:52 AM
View Your Photos More Efficiently With PhotoCal App! alfred1986 iPhone and iPod touch Apps 0 Apr 23, 2013 01:25 AM
How to migrate files to new iMac most efficiently mackingtosh iMac 21 Dec 4, 2012 01:54 PM

Forum Jump

All times are GMT -5. The time now is 12:23 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC