简体   繁体   English

日历事件应用程序的核心数据谓词

[英]Core data predicate for a calendar event app

I'm a novice programmer and I've been struggling for two weeks on this one issue. 我是一个新手程序员,在这个问题上我已经苦苦挣扎了两个星期。 I'm using JTCalendar from cocoapods. 我正在使用cocoapods的JTCalendar。 It is designed to return a date under - (BOOL)calendarHaveEvent:(JTCalendar *)calendar date:(NSDate *)date { which will appear as a dot on the calendar to show an event. 它旨在返回- (BOOL)calendarHaveEvent:(JTCalendar *)calendar date:(NSDate *)date { ,该- (BOOL)calendarHaveEvent:(JTCalendar *)calendar date:(NSDate *)date {将在日历上显示为一个点以显示事件。 To save my event I use the following code: 为了保存事件,我使用以下代码:

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
                 NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *savedate;
                 savedate = [NSEntityDescription insertNewObjectForEntityForName:@"AlarmData" inManagedObjectContext:context];
                 [savedate setValue:CT forKey:@"alarmDate"];

                 [context save:&error];

                BOOL isSaved = [appDelegate.managedObjectContext save:&error];

                 NSLog(@"success!!!!, %@", savedate);

and the following to attempt to fetch the date and "return" it: 以下尝试获取日期并“返回”日期:

' '

- (BOOL)calendarHaveEvent:(JTCalendar *)calendar date:(NSDate *)date
{
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];





    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:[NSDate date]]];
    NSLog(@"Date %@",textDate);

     NSDate *startDate = [dateFormatter dateFromString:@"31-12-1981"];
    NSDate *endDate = [dateFormatter dateFromString:@"31-12-2999"];


    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(alarmDate >= %@) AND (date <= %@)", startDate, endDate];

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:[NSEntityDescription entityForName:@"AlarmData" inManagedObjectContext:context]];
    [request setPredicate:predicate];

    NSError *error;
    NSArray *matchingData = [context executeFetchRequest:request error:&error];

        NSString *alarmDate =  [ NSString  stringWithFormat:@"dd-MM-yyyy"];

        for (NSManagedObject *obj in matchingData) {
            alarmDate = [obj valueForKey:@"alarmDate"];

            return alarmDate;'

Sadly the result looks like this, every date seems to be returned with a dot underneath: 可悲的是结果看起来像这样,每个日期似乎都在下面加上一个点:

https://drive.google.com/file/d/0Bw0Kf2Z9-yb8Zm5LWnZUUkRJRzQ/view?usp=sharing https://drive.google.com/file/d/0Bw0Kf2Z9-yb8Zm5LWnZUUkRJRzQ/view?usp=sharing

I only want to have my single date returned, been stuck on this for a long time. 我只想让我的单身约会归来,长期坚持下去。 Thank you! 谢谢!

for (NSManagedObject *obj in matchingData) {
            alarmDate = [obj valueForKey:@"alarmDate"];

            return alarmDate;'

You always return the alamrDate of the first object, no matter what date you have in your method's parameter. 无论方法参数中的日期是什么,都始终返回第一个对象的alamrDate。 Use your parameter to check the date, then return whether there is an alerm for this date or not. 使用参数检查日期,然后返回该日期是否有警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM