Permalink
Browse files

Added category with methods to use with CoreData

  • Loading branch information...
rvenable committed Apr 14, 2011
1 parent 2835051 commit ca63a2a9d80f56faa2380bfdea61fc3860f8c5e6
@@ -0,0 +1,21 @@
+//
+// BfoxRef+CoreData.h
+// BiblefoxBrowser
+//
+// Created by Richard Venable on 4/13/11.
+// Copyright 2011 Epicfox. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreData/CoreData.h>
+#import "BfoxRef.h"
+
+@interface BfoxRef (CoreData)
+
+- (NSMutableArray *)insertEntitiesForName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext;
+- (NSMutableArray *)insertEntitiesForName:(NSString *)entityName
+ inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
+ withFirstVerseField:(NSString *)firstVerseField
+ andLastVerseField:(NSString *)lastVerseField;
+
+@end
@@ -0,0 +1,28 @@
+//
+// BfoxRef+CoreData.m
+// BiblefoxBrowser
+//
+// Created by Richard Venable on 4/13/11.
+// Copyright 2011 Epicfox. All rights reserved.
+//
+
+#import "BfoxRef+CoreData.h"
+#import "BfoxVerseList+CoreData.h"
+
+@implementation BfoxRef (CoreData)
+
+- (NSMutableArray *)insertEntitiesForName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
+{
+ return [self insertEntitiesForName:entityName inManagedObjectContext:managedObjectContext withFirstVerseField:@"firstVerseIndex" andLastVerseField:@"lastVerseIndex"];
+}
+
+- (NSMutableArray *)insertEntitiesForName:(NSString *)entityName
+ inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
+ withFirstVerseField:(NSString *)firstVerseField
+ andLastVerseField:(NSString *)lastVerseField
+{
+ return [self.verseList insertEntitiesForName:entityName inManagedObjectContext:managedObjectContext withFirstVerseField:firstVerseField andLastVerseField:lastVerseField];
+}
+
+
+@end
@@ -0,0 +1,20 @@
+//
+// BfoxVerseList+CoreData.h
+// BiblefoxBrowser
+//
+// Created by Richard Venable on 4/13/11.
+// Copyright 2011 Epicfox. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreData/CoreData.h>
+#import "BfoxVerseList.h"
+
+@interface BfoxVerseList (CoreData)
+
+- (NSMutableArray *)insertEntitiesForName:(NSString *)entityName
+ inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
+ withFirstVerseField:(NSString *)firstVerseField
+ andLastVerseField:(NSString *)lastVerseField;
+
+@end
@@ -0,0 +1,31 @@
+//
+// BfoxVerseList+CoreData.m
+// BiblefoxBrowser
+//
+// Created by Richard Venable on 4/13/11.
+// Copyright 2011 Epicfox. All rights reserved.
+//
+
+#import "BfoxVerseList+CoreData.h"
+
+@implementation BfoxVerseList (CoreData)
+
+- (NSMutableArray *)insertEntitiesForName:(NSString *)entityName
+ inManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
+ withFirstVerseField:(NSString *)firstVerseField
+ andLastVerseField:(NSString *)lastVerseField
+{
+ NSMutableArray *entities = [NSMutableArray arrayWithCapacity:verse_list->ranges.size()];
+ for (std::list<Bfox::Range>::iterator it = verse_list->ranges.begin(); it != verse_list->ranges.end(); it++) {
+ Bfox::Range range = *it;
+
+ id entity = [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:managedObjectContext];
+ [entity setValue:[NSNumber numberWithInt:range.first] forKey:firstVerseField];
+ [entity setValue:[NSNumber numberWithInt:range.last] forKey:lastVerseField];
+ [entities addObject:entity];
+ }
+
+ return entities;
+}
+
+@end

0 comments on commit ca63a2a

Please sign in to comment.