Discussion in 'Mac Programming' started by KieferThomas, Mar 4, 2013.

  1. KieferThomas, Mar 4, 2013
    Last edited: Mar 6, 2013

    macrumors newbie

    Mar 27, 2012
    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:mad:"Entity"

    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...

  2. macrumors regular

    Mar 2, 2013
    I dont get what you mean by moving to the new record for editing, but something that is just weird is

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

    NSManagedObject *Entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entity"
  3. thread starter macrumors newbie

    Mar 27, 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.

  4. macrumors member

    Jun 4, 2009
    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:

    Entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entity"
    Entry = Entry;
  5. macrumors 604


    Nov 26, 2007
    But the variable type declaration was on the far left...
  6. macrumors member

    Jun 4, 2009
    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.

Share This Page