Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 232621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:01:59+00:00 2026-05-11T20:01:59+00:00

***** EDIT ***** What I’m not sure of is how to access an entity

  • 0

***** EDIT *****
What I’m not sure of is how to access an entity from the model in the code, and how to access a specific instance of an entity in that code. That sums up the main issues I’m having.

***** END EDIT *****

I have a tableview with a button to add to it. When the button is clicked, the user is presented with an open dialog where they select a file(s). A new Object is added to the array controller. What I’m not sure how to do is to edit the core data attributes for this new object. There are two attributes, filename and pathname, and I’m not sure how to edit them. If you look at the bottom of the openPanelDidEnd:returnCode:contextInfo: function you’ll see what I’m trying to accomplish.

- (IBAction)addAttachment:(id)sender
{
    panel = [NSOpenPanel openPanel];
    [panel beginSheetForDirectory:nil
                 file:nil
              modalForWindow:[NSApp mainWindow]
            modalDelegate:self
             didEndSelector:@selector(openPanelDidEnd:
                            returnCode:
                            contextInfo:)
              contextInfo:NULL];
}

- (void)openPanelDidEnd:(NSOpenPanel *)openPanel
             returnCode:(int)returnCode
             contextInfo:(void *)x
{
    if (returnCode == NSOKButton)
    {
        NSArray *files = [openPanel filenames];

        int i;
        for (i = 0; i < [files count]; i++)
        {
            NSString *file = [files objectAtIndex:i];
            [attachmentController add:x];
            // How do I add filenames here?
            // I'm assuming it involves KVC like
            // [something setValue:@"file" forKey:@"filename"];
            // But I don't know hot to get the something
            // i.e. since I have multiple attachments,
            // how do I get the one I just created
        }
    }
}

*********** EDIT **************
Simplified, my model has 2 entities: Attachment and Item. Item has a to-many relationship with Attachment, as each Item may have many Attachment’s.

My openPanelDidEnd:returnCode:contextInfo: method now looks like this:

        NSString *filename = [files objectAtIndex:i];
        MySchoolPlanner_AppDelegate *myAppDelegate = [[MySchoolPlanner_AppDelegate init] alloc];
        [NSEntityDescription insertNewObjectForEntityForName:@"Attachment"
                                      inManagedObjectContext:[myAppDelegate managedObjectContext]];
        [myAppDelegate release];

For some reason, the table view bound to the Attachment array controller does not add any. Also, I’m not sure how to access the attachment I just created to use KVC on it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:01:59+00:00Added an answer on May 11, 2026 at 8:01 pm

    NSArray’s add: method is something you’d hook a button up to, when you have a Core Data entity that can be created and used without any initialization. In this case just call NSEntityDescription’s

    + (id)insertNewObjectForEntityForName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)context
    

    with the managed object context you’re using with your array controller and the appropriate entity name to create your managed object in code. You can set properties on it directly if you’ve created a subclass for your entity, or just use key value coding if you haven’t done that yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Sorry about ellipsis that's not what I actually have. For declaring an array
Edit: From another question I provided an answer that has links to a lot
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
Edit : Array should be CvMat or IplImage is not an error message specific
edit: To prevent everyone from reading too much: The problem is that i do
EDIT: I was an idiot. I simply had an image that was vertically long,
EDIT: See my answer below--> I am wanting to have a view that when
Edit (updated question) I have a simple C program: // it is not important
EDIT: iam using ajax to load text in my content that is why onload
Edit : Note that, as Daniel and latkin noted in an answer and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.