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

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 4, 2013, 08:51 PM   #1
KieferThomas
macrumors newbie
 
Join Date: Mar 2012
insertNewObjectForEntityForName

Hello all,

I am using the following code in a project to insert a new record from a button click:

NSManagedObject *Entry = Entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entity"
inManagedObjectContext:context];

This code is working to add a new record to my database when I click my button.

It is not moving to the new record for editing.

I do not know how to explain this better then I have other then for the fact of after the record is inserted into the database I physically have to click on my table or use my move next or move previous buttons to get to the new record... The new record is not moved to automatically to start editing...

Thanks,
Kiefer

Last edited by KieferThomas; Mar 6, 2013 at 07:07 PM. Reason: Need to clarify better then what I have already done...
KieferThomas is offline   0 Reply With Quote
Old Mar 4, 2013, 10:25 PM   #2
Sonnestah
Banned
 
Join Date: Mar 2013
I dont get what you mean by moving to the new record for editing, but something that is just weird is

Code:
NSManagedObject *Entry = Entry =
This doesnt make sense, just use Entry once:

Code:
NSManagedObject *Entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entity"
inManagedObjectContext:context];
Sonnestah is offline   0 Reply With Quote
Old Mar 5, 2013, 07:07 AM   #3
KieferThomas
Thread Starter
macrumors newbie
 
Join Date: Mar 2012
I dont get what you mean by moving to the new record for editing

Thanks for your response Sonnestah,

What I am speaking of: "moving to the new record" is I have to physically click on my table to get to the new record so I can enter my information in the empty fields. The above code does not clear my fields and set the new record as active.

My goal with the code is as if I had linked my button in IB, right clicking and connecting to the ArrayController and making the Add connection. When I do this a new record is inserted and the first field is selected for input into the new record.

The reason I am not doing the a fore mentioned is I am needing control over the newly inserted record for inserting date/time and setting focus to a specific field to continue editing.

The help with getting the new record active is what I need help with.

The point you picked out was corrected. I am not sure why the program didn't crash on compile. But with the correction the program is still doing the same as it was before.

Thanks,
Keith
KieferThomas is offline   0 Reply With Quote
Old Mar 5, 2013, 10:15 AM   #4
cqexbesd
macrumors member
 
Join Date: Jun 2009
Quote:
Originally Posted by KieferThomas View Post
I am not sure why the program didn't crash on compile. But with the correction the program is still doing the same as it was before.
It compiled because it is a valid expression. It will be evaluated from right to left so whilst redundant the extra assignment doesn't have any effect.

So the code becomes, more or less:

Code:
Entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entity"
inManagedObjectContext:context];
Entry = Entry;
cqexbesd is offline   0 Reply With Quote
Old Mar 5, 2013, 11:10 AM   #5
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by cqexbesd View Post
It compiled because it is a valid expression. It will be evaluated from right to left so whilst redundant the extra assignment doesn't have any effect.

So the code becomes, more or less:

Code:
Entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entity"
inManagedObjectContext:context];
Entry = Entry;
But the variable type declaration was on the far left...
ArtOfWarfare is offline   0 Reply With Quote
Old Mar 17, 2013, 12:49 PM   #6
cqexbesd
macrumors member
 
Join Date: Jun 2009
Quote:
Originally Posted by ArtOfWarfare View Post
But the variable type declaration was on the far left...
Declaring a variable tells the compiler you need a bit of space to store some data. That is read at compile time and whatever needs setting up is set up. A variable declaration doesn't become a series of assembler instructions in the way an operation or function call does. Therefore the variable exists (i.e. some memory is reserved to store it), often from the moment the function is entered, but at least from the place where you declared it - certainly before your code that accesses it is run.
cqexbesd is offline   0 Reply With Quote

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

Tags
records inssert moveto

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 06:42 AM.

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

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