アプリを実行すると、「CoreData: エラー: NSManagedObject クラス "Ambulance" で指定された初期化子を呼び出せませんでした」というエラーが発生し続けます。スタックオーバーフローでこの問題をすでに見ましたが、私の場合、解決策を実装する方法がわかりません。何か案は?
救急車.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Ambulance : NSManagedObject
@property (nonatomic, retain) NSString * ambulanceID;
@property (nonatomic, retain) NSNumber * distance;
@property (nonatomic, retain) NSNumber * etaDistance;
@property (nonatomic, retain) NSString * emsID;
@property (nonatomic, retain) NSString * lat;
@property (nonatomic, retain) NSString * lng;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * occupancy;
@property (nonatomic, retain) NSString * type;
@property (nonatomic, retain) NSString * websocketServer;
@property (nonatomic, retain) NSNumber * seconds;
@property (nonatomic, retain) id eta;
+(Ambulance *)nearestAmbulanceByType:(NSString *)type;
- (id)initWithCoder:(NSCoder *)decoder;
- (void)encodeWithCoder:(NSCoder *)encoder;
@end
Ambulance.m
#import "Ambulance.h"
@implementation Ambulance
@synthesize ambulanceID;
@synthesize distance;
@synthesize etaDistance;
@synthesize emsID;
@synthesize lat;
@synthesize lng;
@synthesize name;
@synthesize occupancy;
@synthesize type;
@synthesize websocketServer;
@synthesize seconds;
@synthesize eta;
+(Ambulance *)nearestAmbulanceByType:(NSString *)type {
NSArray *sortedArray = [Ambulance findByAttribute:@"type" withValue:type andOrderBy:@"distance" ascending:YES];
return [sortedArray first];
}
- (void)encodeWithCoder:(NSCoder *)encoder {
//Encode properties, other class variables, etc
[encoder encodeObject:self.ambulanceID forKey:@"ambulanceID"];
[encoder encodeObject:self.distance forKey:@"distance"];
[encoder encodeObject:self.etaDistance forKey:@"etaDistance"];
[encoder encodeObject:self.emsID forKey:@"emsID"];
[encoder encodeObject:self.lat forKey:@"lat"];
[encoder encodeObject:self.lng forKey:@"lng"];
[encoder encodeObject:self.name forKey:@"name"];
[encoder encodeObject:self.occupancy forKey:@"occupancy"];
[encoder encodeObject:self.type forKey:@"type"];
[encoder encodeObject:self.websocketServer:@"websocketServer"];
[encoder encodeObject:self.seconds forKey:@"seconds"];
[encoder encodeObject:self.eta forKey:@"eta"];
}
- (id)initWithCoder:(NSCoder *)decoder {
if((self = [super init])) {
//decode properties, other class vars
self.ambulanceID = [decoder decodeObjectForKey:@"ambulanceID"];
self.distance = [decoder decodeObjectForKey:@"distance"];
self.etaDistance = [decoder decodeObjectForKey:@"etaDistance"];
self.emsID = [decoder decodeObjectForKey:@"emsID"];
self.lat = [decoder decodeObjectForKey:@"lat"];
self.lng = [decoder decodeObjectForKey:@"lng"];
self.name = [decoder decodeObjectForKey:@"name"];
self.occupancy = [decoder decodeObjectForKey:@"occupancy"];
self.type = [decoder decodeObjectForKey:@"type"];
self.websocketServer = [decoder decodeObjectForKey:@"websocketServer"];
self.seconds = [decoder decodeObjectForKey:@"seconds"];
self.eta = [decoder decodeObjectForKey:@"eta"];
}
return self;
}