在我的一个类中,我从NSMutableArray
更改为NSMutableDictionary
。
之前,我访问这样的其他类对象:当从NSMutableArray更改为NSMutableDictionary时访问对象
tmpDeadline = [_taskDays[i] deadline]; //deadline is a object of another class
和访问方法是这样的:
[_taskDays[datePlace]addDatedTask:d]; //addDatedTask is a method in another class
但现在,因为我得到了很多的错误,我不能再这样下去了,我真的不知道如何处理。
我所知道的是,我希望使用其他类的“截止日期”作为键和类的实例作为对象。
这里是给我的问题的评论ERROR代码(我已经给出了代码:
#import "LIUTaskCalendar.h"
#import "LIUTaskDay.h"
#import "LIUDatedTask.h"
@interface LIUTaskCalendar()
{
NSMutableDictionary *_taskDays;
}
@end
@implementation LIUTaskCalendar
- (void)addDatedTasks:(LIUDatedTask *)d {
if (!_taskDays) {
_taskDays = [[NSMutableDictionary alloc] init];
}
NSInteger length = [_taskDays count];
NSDate *tmpDeadline;
NSDate *tmpDueDate;
NSInteger dateExist = 0;
NSInteger datePlace = 0;
NSDate *tmp;
for (int i = 0; i < length; i++) {
tmpDueDate = d.dueDate;
tmpDeadline = [_taskDays[i] deadline]; //*ERROR*
if ([tmpDueDate compare:tmpDeadline] == NSOrderedAscending) {
continue;
} else if ([tmpDueDate compare:tmpDeadline] == NSOrderedDescending) {
continue;
} else {
dateExist = 1;
datePlace = i;
break;
}
}
if (dateExist == 1) {
[_taskDays[datePlace]addDatedTask:d]; //*ERROR*
} else {
LIUTaskDay *tmpLIUTaskDay = [[LIUTaskDay alloc]init];
[tmpLIUTaskDay addDatedTask:d];
tmpLIUTaskDay.deadline = d.dueDate;
//[_taskDays setObject:d forKey:tmpLIUTaskDay.deadline];
[_taskDays addObject:tmpLIUTaskDay]; //*ERROR*
}
}
- (void)removeTaskDay:(NSDate *)date {
NSDate *tmpDeadline;
NSDate *tmpDeleteDate;
NSInteger dateExist = 0;
NSDate *dateDelete;
NSInteger length = [_taskDays count];
for (int i = 0; i < length; i++) {
tmpDeleteDate = date;
tmpDeadline = [_taskDays[i] deadline]; //*ERROR*
if ([tmpDeleteDate compare:tmpDeadline] == NSOrderedAscending) {
continue;
} else if ([tmpDeleteDate compare:tmpDeadline] == NSOrderedDescending) {
continue;
} else {
dateExist = 1;
break;
}
}
if (dateExist == 1) {
//[_taskDays removeObjectForKey:dateDelete];
[_taskDays removeObjectAtIndex:dateDelete]; //*ERROR*
} else {
return;
}
}
@end
如果你需要我可以提供代码为其他类的话就不要
毫不犹豫地告诉我。
在此先感谢
UPDATE
从此改变:
[_taskDays addObject:tmpLIUTaskDay];
要这样:
[_taskDays setObject:d forKey:tmpLIUTaskDay.deadline];
你为什么从阵列改变它的字典吗? – trojanfoe
因为使用日期可以更容易地从日历中访问任务:) – MrNaitX
那么字典的关键是每月的哪一天?我认为这不会让事情变得更容易。你有没有在同一天考虑多项任务? – trojanfoe