我正在使用核心數據來保存一些字符串。我呼籲以下效果一流核心數據無法識別的選擇器錯誤
Results.h
#import <CoreData/CoreData.h>
@interface Results : NSManagedObject
@property(nonatomic, retain) NSString *lessondate;
@property(nonatomic, retain) NSString *lesson;
@property(nonatomic, retain) NSString *location;
@property(nonatomic, retain) NSString *start;
@property(nonatomic, retain) NSString *end;
@end
Results.m
#import "Results.h"
@implementation Results
@dynamic lessondate;
@dynamic lesson;
@dynamic location;
@dynamic start;
@dynamic end;
@end
以下是我的代碼執行保存:
-(void)saveLesson{
Results *result = (Results *)[NSEntityDescription insertNewObjectForEntityForName:@"Diary" inManagedObjectContext:managedObjectContext];
result.lessondate = calendarDateString;
result.lesson = [NSString stringWithFormat:@"%@", lessonText.text];
result.location = [NSString stringWithFormat:@"%@", locationTest.text];
result.start = [NSString stringWithFormat:@"%@", startTimeText.text];
result.end = [NSString stringWithFormat:@"%@", endTimeText.text];
NSError *error;
// here's where the actual save happens, and if it doesn't we print something out to the console
if (![managedObjectContext save:&error])
{
NSLog(@"Problem saving: %@", [error localizedDescription]);
}
[self dismissViewControllerAnimated:YES completion:nil];
}
但是當我嘗試將數據保存在應用程序,該應用程序崩潰,並顯示這些錯誤
2013-02-18 11:46:25.705 After managedObjectContext: <NSManagedObjectContext: 0x1f892480>
2013-02-18 11:46:33.762 -[NSManagedObject setLesson:]: unrecognized selector sent to instance 0x1f80b380
2013-02-18 11:46:33.764 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject setLesson:]: unrecognized selector sent to instance 0x1f80b380'
有人能告訴我這是爲什麼崩潰?完全相同的代碼是在另一個應用程序,並且工作正常。
你在哪裏實現了'setLesson'? – 2013-02-18 12:03:01
您是否在覈心數據的實體中創建了名爲lesson的屬性? – 2013-02-18 12:03:01
另外,你的錯誤說你發送了'setLesson',但是如果你把它叫做'saveLesson'可能會導致你一些問題。 – 2013-02-18 12:04:57