ile çoktan çok ilişki İçinde şu JSON için ilişkileri bir CoreData destekli modelle eşleştirmeye çalışıyorum. Ben RestKit en OM2 sınıflarıyla eşlediysenizRestKit
{
"photos": [
{
"id": 1,
"thumb": "http://localhost/test_1_thumb.png",
"image": "http://localhost/test_1.png",
"date": "2011-07-02T06:06:16Z",
"likes": 0,
"user": {
"id": 1,
"username": "User1",
"avatar": "http://cdn.domain.com/avatar.jpg"
},
"comments": [
{
"date": "2011-07-02T06:06:16Z",
"text": "This is the only comment",
"id": 1,
"author": {
"username": "User1",
"id": 1,
"avatar": "http://cdn.domain.com/avatar.jpg"
}
}
]
}
]
}
My CoreData modeller:
İşte JSON var.
Fotoğraf sınıfı. Ben bu hata ile, bir fotoğrafın comments
özniteliği ancak tüm erişebilecek olduğum Bununla
// Map relationships between entities.
[commentMapping mapKeyPath:@"author" toRelationship:@"author" withMapping:userMapping];
[photoMapping mapKeyPath:@"user" toRelationship:@"owner" withMapping:userMapping];
[photoMapping mapKeyPath:@"comments" toRelationship:@"comments" withMapping:commentMapping];
:
@interface Photo : NSManagedObject
@property (nonatomic, retain) NSString * thumbnailUrl;
@property (nonatomic, retain) NSString * imageUrl;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSNumber * likes;
@property (nonatomic, retain) NSNumber * photoID;
@property (nonatomic, retain) User *owner;
@property (nonatomic, retain) NSSet *comments;
@end
@interface Photo (CoreDataGeneratedAccessors)
- (void)addCommentsObject:(Comment *)value;
- (void)removeCommentsObject:(Comment *)value;
- (void)addComments:(NSSet *)values;
- (void)removeComments:(NSSet *)values;
@end
@implementation Photo
@dynamic thumbnailUrl;
@dynamic imageUrl;
@dynamic date;
@dynamic likes;
@dynamic photoID;
@dynamic owner;
@dynamic comments;
@end
Şimdi tamamen emin değilim parçası ilişkilerdir
Comments = Relationship 'comments' fault on managed object
. Bu bir NSSet olarak tanımlanan
comments
Fotoğraf modeliyle ilgili bir ilişki var veya ilişki eşleme ile yanlış bir şey yapıyorum ama emin değilim.
Beni kurtardın, çok teşekkürler! –