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

  • SEARCH
  • Home
  • 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 8446947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:03:44+00:00 2026-06-10T10:03:44+00:00

I am using a WCF service in my app.When the app is run for

  • 0

I am using a WCF service in my app.When the app is run for the first time on the iPad,I want it to call a WCF service and display the result in a UITableView.Alongwith displaying the data in UITableView,i want to store the data in Core Data so when the user is “offline”(not connected to wifi)the data will be displayed from the Core Data.The AppDelegate.m looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];  
    if (![defaults objectForKey:@"firstRun"])
    {
        self.firstRun = TRUE;
        [defaults setObject:[NSDate date] forKey:@"firstRun"];
    }
    else
    {
       self.firstRun = FALSE;//flag does exist so this ISNT the first run
    }
   [[NSUserDefaults standardUserDefaults] synchronize];
}

The code in UITableView looks like this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [my_table setDataSource:self];
    [my_table setDelegate:self];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if (appDelegate.firstRun){
        NSLog(@"IS FIRST RUN");
        EDViPadDocSyncService *service = [[EDViPadDocSyncService alloc]init];
        [service getAllCategories:self action:@selector(handleGetAllCategories:)];
    }
    else 
    {
        NSLog(@"NOT FIRST RUN");
        NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        NSEntityDescription *entity = [NSEntityDescription
                                       entityForName:@"Categories" inManagedObjectContext:managedObjectContext];
        [fetchRequest setEntity:entity];
        NSError *errormsg;
        self.allCats = [managedObjectContext executeFetchRequest:fetchRequest error:&errormsg];
        NSLog(@"allCATS=%@",self.allCats);
        self.title = @"Categories";
    }
}

-(void)handleGetAllCategories:(id)value
{
    if([value isKindOfClass:[NSError class]])
    {
        NSLog(@"This is an error %@",value);
        return;
    }

    if([value isKindOfClass:[SoapFault class]])
    {
        NSLog(@"this is a soap fault %@",value);
        return;
    }
    NSMutableArray *result = (NSMutableArray*)value;

    NSMutableArray *categoryList = [[NSMutableArray alloc] init];
    NSMutableArray *docCount = [[NSMutableArray alloc]init];
    NSMutableArray *catIdList = [[NSMutableArray alloc]init];

    self.myData = [[NSMutableArray array] init];
    self.myDocCount = [[NSMutableArray array]init];
    self.catId = [[NSMutableArray array]init];

    for (int i = 0; i < [result count]; i++)
    {
        EDVCategory *catObj = [[EDVCategory alloc]init];
        catObj = [result objectAtIndex:i];
        [categoryList addObject:[catObj categoryName]];
        [docCount addObject:[NSNumber numberWithInt:[catObj docCount]]];
        [catIdList addObject:[NSNumber numberWithInt:[catObj categoryId]]];
    }

    self.myData = categoryList;
    self.myDocCount = docCount;
    self.catId = catIdList;
    [my_table reloadData];

    /*store data in Core Data - START*/
    NSManagedObjectContext *context = [self managedObjectContext];
    NSManagedObject *newCategory;
    for(int j=0;j<[result count];j++)
    {
        newCategory = [NSEntityDescription insertNewObjectForEntityForName:@"Categories" inManagedObjectContext:context];
        /*HOW TO STORE DATA FOR THE "CATEGORIES" OBJECT IN CORE DATA*/
    }
    /*store data in Core Data - END*/
}

I am not able to figure out how to store the data received from the wcf service to the core data object directly.I know how to store it from a text box on the screen to a core data object.eg.:-

coreDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newCat = [NSEntityDescription insertNewObjectForEntityForName:@"Categories" inManagedObjectContext:context];
[newCat setValue:name.text forKey:@"name"];
name.text = @"";
[context save:&error];

But this doesn’t help in my case.Any help is appreciated.

  • 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-10T10:03:46+00:00Added an answer on June 10, 2026 at 10:03 am

    You are mixing networking and UI code. It is a recipe for unmaintainable code.

    Your UI should be looking at Core Data and only Core Data to display its data.

    Separately, and asynchronously you should be requesting data from WCF and pushing it into Core Data.

    Your UI does not need to care about first run vs. subsequent run. It just looks at Core Data via a NSFetchedResultsController.

    Your network code is the only part that cares about new vs. update.

    Update 1

    how can I achieve this? When the app is running and connected to WiFi,it has to get the latest data from the WCF service.

    NSURLConnection can do async requests built-in. I generally recommend writing your networking code as NSOperation subclasses and then put them into a queue.

    It appears that WCF can return XML and takes standard HTTP requests. Therefore you can write NSOperation subclasses that build your request, send it to the server and wait for a reply. When the reply comes you parse the XML and insert it into Core Data. When you save the Core Data NSManagedObjectContext your NSFetchedResultsController instances will automatically fire and allow you to update your UI.

    I have several code samples that perform these feats although they are written for JSON responses as opposed to XML responses. It would not be difficult to take those examples and alter them to your needs.

    You can start with this stackoverflow question and its response.

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

Sidebar

Related Questions

We're using the castle scheduler component: http://using.castleproject.org/display/Comp/Castle.Components.Scheduler?showChildren=false I have a wcf service which creates
I've got an app which is using a WCF service. Now I'd like to
We are using WCF service on the client side we are planning to explicitly
Hi We developed web service using WCF service and hosted on Windows 2003 server
I have developed a Web service using WCF Service Application. This service application is
I get a CommunicationException while using WCF service. The message is: The remote endpoint
I am using a WCF Service and I have implemented IErrorHandler . In the
I am using a WCF service to expose certain Active Directory management functions to
I am using a WCF service and a Silverlight Client sending data to the
I am using calling web services and using WCF generated service-reference on the client.

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.