ash007
ash007

Reputation: 333

How to fill core data into local table of Azure Mobile Services

I have an MSSyncTable* table instance variable inside all ViewController. Currently I am fetching data directly from server and filling this table using pullWithQuery function.

- (void)syncTableData:(ESCompletionBlock)completion
{
    MSQuery *query = [self.table query];

    // Pulls data from the remote server into the local table.
    // We're pulling all items 
    [self.table pullWithQuery:query queryId:@"EventTable" completion:^(NSError *error) {
        [self logErrorIfNotNil:error];
        // Let the caller know that we finished
        dispatch_async(dispatch_get_main_queue(),completion );
}];

I want to change this approach and fill the table with data fetched from my core data. I have filled the core data with the data I require to be showed on the screen.

How do I make table get data from Core Data?

Upvotes: 0

Views: 208

Answers (2)

Eric Hedstrom
Eric Hedstrom

Reputation: 1627

When you call

-(void)readWithPredicate:(NSPredicate *)predicate completion:(MSReadQueryBlock)completion

or

-(void)readWithId:(NSString *)itemId completion:(MSItemBlock)completion

or

-(void)readWithCompletion:(MSReadQueryBlock)completion

on your MSSyncTable* table, that will query the local Core Data copy of your sync table and return the results in the completion block. You may also want to create your own NSManagedObjectContext for the local Core Data store to get the items as NSManagedObjects, but be sure to make any changes to the objects via the MSSyncTable.

Upvotes: 0

Adrian Hall
Adrian Hall

Reputation: 8035

The point of the pullWithQuery call is to pull data from your remote azure app service to be stored within core data. Once you do that, the standard table calls will use core data instead.

See this for a tutorial on offline sync: https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-ios-get-started-offline-data

Upvotes: 1

Related Questions