返回null值的方法

时间:2014-11-14 09:26:30

标签: ios objective-c xcode ekevent

下面的方法是返回nil值,我观察到当方法在块中运行时,方法返回值而没有激励。

首先返回_cards然后nlog正在打印。

这个setter方法和我如何在这里使用完成hadler

请帮忙解决此问题。 Thaks in Advance

- (NSMutableArray *)cards
    {
        if (_cards) return _cards;
        EKEventStore *eventStore = [[EKEventStore alloc] init];
        if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
            _cards = [[NSMutableArray alloc] init];
            [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
                /* This code will run when uses has made his/her choice */

                NSString * myString = @"2014-01-01";
                NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
                dateFormatter.dateFormat = @"yyyy-MM-dd";
                NSDate *startDate = [dateFormatter dateFromString:myString];

                NSDate *endDate = [[NSDate alloc] init];

                //   NSArray *calendars = [eventStore calendars];
                NSArray *calendars = [eventStore calendarsForEntityType:EKCalendarChooserDisplayAllCalendars];
                NSLog(@"Calendars %@",calendars);
                NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:startDate
                                                                             endDate:endDate calendars:calendars];
                matchingEvents = [eventStore eventsMatchingPredicate:predicate];
                NSIndexPath * indexpath;
                NSString * event = [[matchingEvents objectAtIndex:indexpath.row] valueForKey:@"title"];
                EKEvent *anEvent;
                NSLog(@"Total Events >> %lu",(unsigned long)[matchingEvents count]);

                for (int j=0; j < [ matchingEvents count]; j++) {
                    [_cards addObject:@(ANDYCardStateNormal)];

                    anEvent = [matchingEvents objectAtIndex:j];
                    NSLog(@"Title >>>%@",anEvent.title);
                    NSLog(@"start date is %@ \n End Date is >>> %@",anEvent.startDate,anEvent.endDate);

                }
            }];
        }

        return _cards;
    }

0 个答案:

没有答案