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 7663515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:04:33+00:00 2026-05-31T14:04:33+00:00

I created an object that contains properties that in the end will manage data

  • 0

I created an object that contains properties that in the end will manage data that lives in core data.

I would like to create methods within this object to set data that would be saved into core data as well as method that gets all data from core data and sets properties in the object so I can have everything contained in one object.

The object I am using to set the object’s properties is not setting it properly. It will set them within part of the method but in another part of the method and outside of the method the properties are null.

It is a scoping problem that I clearly do not have my head around so I am turning to the experts. Please advise where I have gone astray. Thanks again for your assistance in advance!
Ed

Object Definitions:
.m file

 @implementation GenObject

 @synthesize name = _name;
 @synthesize address = _address;

 - (void)getGenData
 {
      MyAppDelegate *genDataAppDelegate = [[UIApplication sharedApplication] delegate]; // Create a variable to the app delegate
      NSManagedObjectContext *genDataContext = [genDataAppDelegate managedObjectContext]; // Create a context

      NSEntityDescription *getDataEntityDesc = [NSEntityDescription entityForName:@"GeneralData" inManagedObjectContext:genDataContext];  // Create a description for the core data
      NSFetchRequest *genDataRequest = [[NSFetchRequest alloc] init]; // Create a Fetch request for the core data

      [genDataRequest setEntity:getDataEntityDesc]; // Set the fetch requests entity description

      NSManagedObject *genDataMatches = nil; // Create a managed object
      NSError *genDataCoreError; // Create an error object

      NSArray *genDataCoreObjectsArray = [genDataContext executeFetchRequest:genDataRequest error:&genDataCoreError]; // Fetch the core data and load the objects array
      int genDataCoreObjectsCount = [genDataCoreObjectsArray count]; // Get the count of the objects fetched

      if ([genDataCoreObjectsArray count] == 0) // Check to see if there were any objects fetched
      {
          //NSLog(@"No matches");
      } 
      else // If there were objects fetched then loop over them
     {
         for(int y = 0; y < genDataCoreObjectsCount; y++) // Loop over the objects fetched
         {
             genDataMatches = [genDataCoreObjectsArray objectAtIndex:y]; // Get the current object
             self.name = [[genDataMatches valueForKey:@"name"] retain];
             self.address = [[genDataMatches valueForKey:@"address"] retain];
             NSLog(@"BASE URL %@",self.baseurl); // WORKS HERE!!!
        }   
    }
    NSLog(@"BASE URL %@",self.baseurl); // DOES NOT WORK HERE!!!
 }
 @end

.h file

 @interface GenObject : NSObject
 {
     NSString    *_name;    
     NSString    *_address;   
 }

 @property (nonatomic, retain) NSString  *name;
 @property (nonatomic, retain) NSString  *address;

 - (void)setGenIntitalData;
 @end

And if I try to call it from within a different class like say a ViewController as such…
NOTE: Within the viewController genDataObj is a property of the viewController

 - (void)viewDidLoad
 {
     self.genDataObj = [GenData new];
     [self.genDataObj setGenIntitalData]; // Setup the gendata core data
     [self.genDataObj getGenData]; // Set up the gen data from the core data

     NSLog(@"NAME: %@", self.genDataObj.name); // NAME IS nil HERE!!!!

     [super viewDidLoad];
 }
  • 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-31T14:04:34+00:00Added an answer on May 31, 2026 at 2:04 pm

    You should confirm that your NSManagedObject is actually returning data. Try this:

     - (void)getGenData
     {
        MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
        NSManagedObjectContext *context = [appDelegate managedObjectContext]; 
        NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"GeneralData"];
    
        NSManagedObject *genData = nil;
        NSError *fetchError = nil;
        NSArray *genDataObjects = [context executeFetchRequest:request error:&fetchError];
        [request release];
        if( fetchError )
            NSLog(@"%s - ERROR fetching genData: %@,%@",__FUNCTION__,fetchError,[fetchError userInfo]);
        else
        {
            if( [genDataObjects count] == 0 )
                NSLog(@"%s - No matches for genData",__FUNCTION__);
            else
            {
                genData = [genDataObjects objectAtIndex:0];
                NSLog(@"%s - genData.name = %@",__FUNCTION__,[genData valueForKey:@"name"]);
                self.name = [genData valueForKey:@"name"];
                self.address = [genData valueForKey:@"address"];
            }
        }
    }
    

    In setGenIntitalData are you saving your changes to the persistent store? I assume that in setGenIntitalData you are creating initial settings; but if the NSManagedObject isn’t saved, then your subsequent fetch will yield invalid data.

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

Sidebar

Related Questions

I'd like to be able to create an object that is created like a
I've created an object that contains another collection in one of it properties. This
If you create a Filter object that contains criteria for Linq that normally goes
I've created a object that I'd like to have accessible from wherever the request-object
I created a list<T> that contains a collection of objects that have this properties:
I have been trying to create a new raster object that contains only a
All of our reports are created from object graphs that are translated from our
I have an object that hasn't been created yet (so it has no ID),
I have an ExpenseType object that I have created with the following migration: class
i have created an IE band object (toolbar) that is working well. however, when

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.