Marcal
Marcal

Reputation: 1371

Cleaning up Database entries

On an App v1.0 I gave the user the possibility to add data on a database, only an attribute at a time. As examaple lets say that the user can add a person name and his/her surname. Later on, let´s say he/she adds the age. The database would look like this:

enter image description here

(where the attibute ´Name´ is unique)

I´m going to update the code so that before saving another attribute (say ´alias´), it will chech whether the name has already been used. If it is, it will add the alias in the same entry and if not, it will create a new one.

What I´d also like to do is to clean up the database. In this example it would merge entries #1 and #2, to get something like:

enter image description here

(former entry #2 would be deleted).

I seem to remember that there was an automatic way to do that, but I´m not sure if I´ve immagined it or it was somewhere else such as MS Access because I cannot find it again.

So, is there a way to do that automatically or should I explore a programatically approach?

Upvotes: 0

Views: 88

Answers (1)

Dhruv
Dhruv

Reputation: 2163

 NSError *err = nil;
 NSUInteger count = [managedObjectContext countForFetchRequest:request error:&err];
 [request release];
 if (!err)
 {
   return count;
 }
  else
   return 0;

Upvotes: 1

Related Questions