Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jul 4, 2011, 04:42 AM   #1
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:

- (IBAction)addNewStudent:(id)sender
        NSArray *studentNames = [[students arrangedObjects] valueForKey:@"name"];
        if ([studentNames containsObject:[sender stringValue]]) {
        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]);
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

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

bindings, cocoa, nsarraycontroller, nscombobox

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
NSComboBox in NSTableView behaving strangely Monaj Mac Programming 0 Jul 4, 2011 10:30 AM
NSMatrix simple binding question Monaj Mac Programming 1 Jun 16, 2011 08:32 AM
Most Efficient Way To Sync Contacts With iPhone knemonic iPhone Tips, Help and Troubleshooting 4 Feb 8, 2011 03:06 PM
Torrent Client VPN Bind & Routing MOD.and.OP Mac Basics and Help 0 Dec 4, 2010 05:11 PM
How to implement copy/paste functionality? Sergio10 iPhone/iPad Programming 2 Aug 20, 2009 03:59 AM

All times are GMT -5. The time now is 08:20 AM.

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

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