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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:48:22+00:00 2026-06-15T09:48:22+00:00

im first time using core data concept to simply insert and retrive some info..

  • 0

im first time using core data concept to simply insert and retrive some info..

i have userInfoAppDelegate.h , userInfoAppDelegate.m and DisplayController.h , DisplayController.m.

now i have succesfully addded and retrived data in my delegate files, here is code

userInfoAppDelegate.h

#import <UIKit/UIKit.h>
#import "HomeController.h"

@class RootViewController;

@interface UserInfoAppDelegate : UIResponder <UIApplicationDelegate>{    
    HomeController *hController;
    UIWindow *Window;        
}    
@property (nonatomic, strong) UINavigationController *navigationController;
@property (nonatomic, strong) RootViewController *rootViewController;        
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;    
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;    
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;

@end

userInfoAppDelegate.m

@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{         
   //some code...

UserInfo *newUser = [NSEntityDescription insertNewObjectForEntityForName:@"UserInfo"
             inManagedObjectContext:self.managedObjectContext];    

if (newUser != nil){             
    newUser.firstName = @"test"; 
    newUser.lastName = @"test";
    newUser.userName=@"b@test.com";
    // newUser.bDate = [NSDate date] ;
    newUser.department=@"Admin";

    NSError *savingError = nil;        
    if ([self.managedObjectContext save:&savingError])
    { 
        NSLog(@"Successfully saved the context."); 
    } 
    else
    { 
        NSLog(@"Failed to save the context. Error = %@", savingError);
    } 
}     

else {        
    NSLog(@"Failed to create the new person.");
}   

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];    

/* Here is the entity whose contents we want to read */ 

NSEntityDescription *entity = [NSEntityDescription entityForName:@"UserInfo"
       inManagedObjectContext:self.managedObjectContext];    

/* Tell the request that we want to read the contents of the Person entity */
[fetchRequest setEntity:entity]; 
NSError *requestError = nil;    

/* And execute the fetch request on the context */ 
NSArray *users = [self.managedObjectContext executeFetchRequest:fetchRequest
                    error:&requestError];

NSLog(@"%@",users);       
if ([users count] > 0){
    NSUInteger counter = 1; 

    for (UserInfo *thisUser in users){            
        NSLog(@"Person %lu First Name = %@", (unsigned long)counter, thisUser.firstName);
        NSLog(@"Person %lu Last Name = %@", (unsigned long)counter,
              thisUser.lastName);
        NSLog(@"Person %lu Department = %@", (unsigned long)counter,
              thisUser.department ); counter++;
    }
}

else { 
    NSLog(@"Could not find any Person entities in the context.");
}

  //some code...

}

// ABOVE CODE WORKED WELL WITH PROPER RESULT , BUT SAME CODE NOT WORKING WITH MY DisplayController.h AND DisplayController.m.

  • 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-06-15T09:48:24+00:00Added an answer on June 15, 2026 at 9:48 am

    Get AppDelegate reference in your controller and then where you are using self.managedObjectContext, use delegate.managedObjectContext

    Here’s a small sample

    userInfoAppDelegate *delegate = (userInfoAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"UserInfo"
           inManagedObjectContext:delegate.managedObjectContext]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using SBJSON and Core Data for the first time. I have a
I am using Core Data for the first time and was just curious if
I am using core data first time in my application for my problem I
I'm working on a recipe book right now using Core Data. It's the first
i am using Core Data for the first time in my iOS application. I
So this is my first time using cookies and i'm having some trouble setting
This is my first time using Google Analytics Ecommerce Tracking to get data for
I'm working on my first app using Core Data and I need to assign
I'm trying to make my first application using Objective C + Core Data, but
This is my first time using StackOverflow myself. I have found many answers to

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.