Instance Method


Fetches all the contexts along a given identifier path.


func contexts(matchingIdentifierPath identifierPath: [String], completion: @escaping ([CLSContext], Error?) -> Void)



An array of strings that trace a path of identifiers from mainAppContext to a target context.


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


Use this method to get all of the named contexts along the identifier path. For example:

let store = CLSDataStore.shared
store.contexts(matchingIdentifierPath: ["game", "level-1"]) { contexts, _ in
    for context in contexts {
// Prints "game" and then "level-1"

The identifier path is taken starting from mainAppContext, which lies at the root of your app’s context hiearchy. For each context that doesn’t exist along the path, the data store calls its delegate’s createContext(forIdentifier:parentContext:parentIdentifierPath:) method to create the context. If contexts are missing and the data store has no delegate, the returned list of contexts is incomplete.

See Also

Finding Contexts That Match Criteria

struct CLSPredicateKeyPath

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