contexts(matchingIdentifierPath:completion:)
Fetches all the contexts along a given identifier path.
Declaration
func contexts(matchingIdentifierPath identifierPath: [String], completion: @escaping @Sendable ([CLSContext], (any Error)?) -> Void)func contexts(matchingIdentifierPath identifierPath: [String]) async throws -> [CLSContext]Parameters
- completion:
A closure that the method calls with the matching contexts and an optional error that indicates the reason for failure, if any.
Discussion
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 {
print(context.identifier)
}
}
// 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.