Instance Method

contextsMatchingPredicate:completion:

Fetches all the contexts matching a predicate.

Declaration

- (void)contextsMatchingPredicate:(NSPredicate *)predicate completion:(void (^)(NSArray<CLSContext *> *contexts, NSError *error))completion;

Parameters

predicate

A predicate that the method uses to search for contexts.

completion

A closure that the method calls with the array of contexts that match the predicate and an optional error that indicates the reason for failure, if any.

Discussion

Use the predicate keys defined in CLSPredicateKeyPath to create a predicate that you pass to this method to search for contexts matching certain criteria.

For example, to print the titles of all the children of the main app context:

let store = CLSDataStore.shared
let predicate = NSPredicate(format: "%K = %@", CLSPredicateKeyPath.parent as CVarArg,
                                               store.mainAppContext)
store.contexts(matching: predicate) { contexts, _ in
    for context in contexts {
        print(context.title)
    }
}

See Also

Finding Contexts That Match Criteria

- contextsMatchingIdentifierPath:completion:

Fetches all the contexts along a given identifier path.

CLSPredicateKeyPath

The set of possible key paths you use to search for contexts.