0

i am currently working on Core Data and i have following code

NSManagedObjectContext *managedObjContxt = [self managedObjectContext];
NSFetchRequest *fetchReq = [[NSFetchRequest alloc] initWithEntityName:@"BDEvent"];
NSMutableArray *fetchedObj= [[managedObjContxt executeFetchRequest:fetchReq error:nil] mutableCopy];

Now my fetchedObj array contains

<_PFArray 0x7b78d4e0>(
<BDEvent: 0x7b78cf40> (entity: BDEvent; id: 0x7b78be60 <x-coredata://066794C5-FA98-4D76-B306-C62CF65563F2/BDEvent/p1> ; data: {
    name = rock;
    status = "D1";
    timestamp = "18-02-2015 12:10:10";
}),
<BDEvent: 0x7b78d1f0> (entity: BDEvent; id: 0x7b78be70 <x-coredata://066794C5-FA98-4D76-B306-C62CF65563F2/BDEvent/p2> ; data: {
    name = Illa;
    status = "D1";
    timestamp = "18-02-2015 12:15:01";
}),
<BDEvent: 0x7b78d290> (entity: BDEvent; id: 0x7b78be80 <x-coredata://066794C5-FA98-4D76-B306-C62CF65563F2/BDEvent/p3> ; data: {
    name = john;
    status = "EXIT|D2";
    timestamp = "18-02-2015 12:25:05";
})
)

Now i want to create 2 array based on status

Array1 will contain timestamp value which does not have EXIT status and Array2 will contain timestamp value which does have EXIT status.

How to achieve this ?

1 Answer 1

1

To get an array with 'Exit' code , add a predicate to your fetch request like this.

    NSManagedObjectContext *managedObjContxt = [self managedObjectContext];
    NSFetchRequest *fetchReq = [[NSFetchRequest alloc] initWithEntityName:@"BDEvent"];

//add this line
    fetchReq.predicate = [NSPredicate predicateWithFormat:@"status contains 'EXIT'"];


    NSMutableArray *fetchedObj= [[managedObjContxt executeFetchRequest:fetchReq error:nil] mutableCopy];

to get an array without 'EXIT' code, use following predicate,

  fetchReq.predicate = [NSPredicate predicateWithFormat:@"NOT (status contains 'EXIT')"];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.