iOS アプリケーションで Core Data を使用しています。私はこのようなモデルを持っています: 私の質問は、どのように自分のデータにアクセスできるかです。たとえば、「id_page」で本を取得する方法は?? 答えてくれてありがとう
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class Note, Page;
@interface Book : NSManagedObject
@property (nonatomic, retain) NSString * id_book;
@property (nonatomic, retain) NSSet *page;
@property (nonatomic, retain) NSSet *note;
-(Note*)noteForPage;
-(Page*)pageForPageNumber:(int)pageNumber;
@end
@interface Book (CoreDataGeneratedAccessors)
- (void)addPageObject:(Page *)value;
- (void)removePageObject:(Page *)value;
- (void)addPage:(NSSet *)values;
- (void)removePage:(NSSet *)values;
- (void)addNoteObject:(Note *)value;
- (void)removeNoteObject:(Note *)value;
- (void)addNote:(NSSet *)values;
- (void)removeNote:(NSSet *)values;
@end
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Page : NSManagedObject
@property (nonatomic, retain) NSString * id_page;
@end
私はこのような本とページを作成しました:
B
ook *book = [NSEntityDescription
insertNewObjectForEntityForName:@"Book"
inManagedObjectContext:context];
Page *page1 = [NSEntityDescription
insertNewObjectForEntityForName:@"Page"
inManagedObjectContext:context];
[page1 setValue:@"firstPage" forKey:@"id_page"];
Page *page2 = [NSEntityDescription
insertNewObjectForEntityForName:@"Page"
inManagedObjectContext:context];
[page2 setValue:@"secondPage" forKey:@"id_page"];
Page *page3 = [NSEntityDescription
insertNewObjectForEntityForName:@"Page"
inManagedObjectContext:context];
[page3 setValue:@"ThirdPage" forKey:@"id_page"];
// create a set of pages
NSSet *pageSets = [[NSSet alloc]initWithObjects:page1,page2,page3, nil];
[book addPage:pageSets];