Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 8, 2012, 02:23 AM   #1
DrakeRamoray
macrumors newbie
 
Join Date: Aug 2012
update my core data database

Hi everyone.

I must to copy datas from my external database to core data and I have a little problem.
I use Json to communicate with iOS and it's work pretty well, each package of datas have an ID number.
I just want to save this datas in the iphone if the ID number is not saved yet on my IOS database.
How can I do?

Thank you
DrakeRamoray is offline   0 Reply With Quote
Old Aug 8, 2012, 01:02 PM   #2
forum user
macrumors regular
 
Join Date: Aug 2008
You might want to look at NSExpression. Something similar to:
Code:
NSExpression * expressionDescriptionCount = 
[NSExpression expressionForFunction:@"count:" 
arguments:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:@"IDnumber"]]];
[fetchRequest setResultType:NSDictionaryResultType];
 NSArray * results = [theContext executeFetchRequest:fetchRequest error:&error];
After the fetch went ok "results" will contain a dictionary.
If the value of the count key inside the dictionary is zero then your "id Number" is not yet present. Otherwise it will be the the nubmer of occurrence.

Ensure you match the string @"IDnumber" in expressionForKeyPath:@"IDnumber" with the correct spelling of the attribute.
__________________
Fuel Log Evo: The Cost Manager App for any Vehicle
forum user is offline   0 Reply With Quote
Old Aug 8, 2012, 03:19 PM   #3
Duncan C
macrumors 6502a
 
Duncan C's Avatar
 
Join Date: Jan 2008
Location: Northern Virginia
 
Quote:
Originally Posted by forum user View Post
You might want to look at NSExpression. Something similar to:
Code:
NSExpression * expressionDescriptionCount = 
[NSExpression expressionForFunction:@"count:" 
arguments:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:@"IDnumber"]]];
[fetchRequest setResultType:NSDictionaryResultType];
 NSArray * results = [theContext executeFetchRequest:fetchRequest error:&error];
After the fetch went ok "results" will contain a dictionary.
If the value of the count key inside the dictionary is zero then your "id Number" is not yet present. Otherwise it will be the the nubmer of occurrence.

Ensure you match the string @"IDnumber" in expressionForKeyPath:@"IDnumber" with the correct spelling of the attribute.

I don't understand the code you posted. You create an NSExpression object, and then you issue a fetch request that doesn't use the expression at all. Aren't you missing code that would add the expression to a predicate, and add the predicate to the fetch request? As written, the code uses an existing fetch request that has nothing to do with the expression object you created.
__________________
Regards,
Duncan Champney, WareTo.
Check out our latest iOS app, Face Dancer, available for free on the App Store.
Duncan C is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Core Data do you have to pull out an object before you can update it? whitedragon101 iPhone/iPad Programming 3 Feb 23, 2014 05:13 PM
Combo Core Data Fetch? (Update: Unsupported function expression count)!? ArtOfWarfare iPhone/iPad Programming 5 Jul 8, 2013 01:21 AM
How to refresh/update Core Data transient property? mdhansen5 iPhone/iPad Programming 2 Aug 5, 2012 12:46 AM
Add or delete Core Data entries in an update? isthisonetaken iPhone/iPad Programming 1 Jul 30, 2012 11:24 AM
Using Core Data to fetch record from SQLite database. kimbebot iPhone/iPad Programming 3 Jun 29, 2012 10:04 AM

Forum Jump

All times are GMT -5. The time now is 02:56 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC