Search code examples
iosxcodeekeventekeventstore

EKEventStore Programming Xcode iOS Asynchronous Search


The Documentation states:

  • (void)enumerateEventsMatchingPredicate:(NSPredicate *)predicate usingBlock:(EKEventSearchCallback)block

This method is synchronous. For asynchronous behavior, run the method on another thread with dispatch_async or NSOperation.

How do you make this asynchronous, the sentence doesn't really demonstrate it. Could anyone clarify?

Thanks

D :-)


Solution

  • either dispatch it all:

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
        ...
        dispatch_async(dispatch_get_global_queue(0,0), ^{
            [store enumerateEventsMatchingPredicate:p usingBlock:^(..) {
                //DO IT
            }];
        });
        ...
    }
    

    or the callbacks

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
        ...
        [store enumerateEventsMatchingPredicate:p usingBlock:^(..) {
            dispatch_async(dispatch_get_global_queue(0,0), ^{
            //DO IT
            });
        }];
    
        ...
    }