코어 데이터를 처음 사용하고 간단한 테스트 응용 프로그램을 작성합니다. 내가 뭘 하려는지 sqlite 데이터베이스에 저장할 수있는 개체가 있습니다.코어 데이터 오브젝트 용 이니셜 라이저 만들기
@property (nonatomic, retain) NSString * address;
@property (nonatomic, retain) NSString * city;
@property (nonatomic, retain) NSNumber * latitude;
@property (nonatomic, retain) NSNumber * longitude;
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * notes;
@property (nonatomic, retain) NSString * state;
@property (nonatomic, retain) NSString * street;
@property (nonatomic, retain) NSString * zip;
이 모든하는 .m 파일에 @dynamic 있습니다
내 속성처럼 보인다.
내가 원래이 한 : 그러나
+ (AddressAnnotation *)initWithPlacemark:(CLPlacemark *)placemark inContext:(NSManagedObjectContext *)context {
AddressAnnotation *anAddress = [NSEntityDescription insertNewObjectForEntityForName:@"AddressAnnotation" inManagedObjectContext:context];
anAddress.address = placemark.subThoroughfare;
anAddress.street = placemark.thoroughfare;
anAddress.city = placemark.locality;
....
return anAddress;
}
을, 나는 나의 선이 표시됩니다 프로토콜의
을 재정의하는 방법을 몰랐다. 그 중 하나는 다음과 같습니다.
- (NSString *)title {
if (self.name) {
return self.name;
}
else {
return @"";
}
}
자막은 매우 비슷하지만 다른 속성과 비슷합니다. 그러나 이것들은 인스턴스 용이고 클래스 객체 용이 아니기 때문에 작동하지 않습니다. 나는이 작업을 수행 할 때
- (AddressAnnotation *)initWithPlacemark:(CLPlacemark *)placemark inContext:(NSManagedObjectContext *)context {
AddressAnnotation *anAddress = [NSEntityDescription insertNewObjectForEntityForName:@"AddressAnnotation" inManagedObjectContext:context];
NSLog(@"placemark: %@", [placemark description]);
anAddress.address = placemark.subThoroughfare;
anAddress.street = placemark.thoroughfare;
...
return anAddress;
}
그러나, 내 모든 값이 널 (null)입니다 :
그래서 나는 같이 내 이니셜을 변경했습니다. 이 상황에서 이니셜 라이저를 작성하는 올바른 방법은 무엇입니까? 감사!
나에게 재미있는 부분은 + 클래스 메서드를 사용하여 객체를 만들 때,지도에 핀을 배치 할 때 viewForAnnotation : 메서드가 호출 될 때 콜 아웃이 표시됩니다. - instance 메서드를 사용할 때 .name 값이 null이므로 설명 선이 표시되지 않습니다. 생각? 감사! – Crystal