Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

add more fields to core data

roryclear7d300ae785c9
diff --git a/SegmentsModel.xcdatamodeld/SegmentsModel.xcdatamodel/contents b/SegmentsModel.xcdatamodeld/SegmentsModel.xcdatamodel/contents
index f667642..18550a3 100644
--- a/SegmentsModel.xcdatamodeld/SegmentsModel.xcdatamodel/contents
+++ b/SegmentsModel.xcdatamodeld/SegmentsModel.xcdatamodel/contents
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24D60" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<entity name="SegmentEntity" representedClassName="SegmentEntity" syncable="YES" codeGenerationType="class">
+ <attribute name="duration" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
+ <attribute name="timeStamp" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="url" optional="YES" attributeType="String"/>
</entity>
</model>
\ No newline at end of file
diff --git a/clearcam/ViewController.m b/clearcam/ViewController.m
index 03d1d87..3793d7c 100644
--- a/clearcam/ViewController.m
+++ b/clearcam/ViewController.m
@@ -49,9 +49,8 @@ NSMutableDictionary *classColorMap;
// Save a new string
NSLog(@"core data segments?:");
//[self deleteAllSegmentsInContext:self.context]; //to delete all
- [self saveURL:@"Rory here???" inContext:self.context];
// Fetch all saved strings
- [self fetchAllStringsInContext:self.context];
+ [self fetchAllSegmentsInContext:self.context];
// coredata stuff
self.current_segment_squares = [[NSMutableArray alloc] init];
@@ -164,8 +163,8 @@ NSMutableDictionary *classColorMap;
}
}
-- (void)fetchAllStringsInContext:(NSManagedObjectContext *)context {
- // Create a fetch request for StringEntity
+- (void)fetchAllSegmentsInContext:(NSManagedObjectContext *)context {
+ // Create a fetch request for SegmentEntity
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"SegmentEntity"];
// Execute the fetch request
@@ -173,12 +172,15 @@ NSMutableDictionary *classColorMap;
NSArray *results = [context executeFetchRequest:fetchRequest error:&error];
if (error) {
- NSLog(@"Failed to fetch strings: %@", error.localizedDescription);
+ NSLog(@"Failed to fetch segments: %@", error.localizedDescription);
} else {
- NSLog(@"Fetched strings:");
+ NSLog(@"Fetched segments:");
for (NSManagedObject *obj in results) {
- NSString *value = [obj valueForKey:@"url"];
- NSLog(@"%@", value);
+ NSString *url = [obj valueForKey:@"url"];
+ double timeStamp = [[obj valueForKey:@"timeStamp"] doubleValue];
+ double duration = [[obj valueForKey:@"duration"] doubleValue];
+
+ NSLog(@"Segment - URL: %@, TimeStamp: %f, Duration: %f", url, timeStamp, duration);
}
}
}
@@ -477,8 +479,21 @@ NSMutableDictionary *classColorMap;
segmentEntry[@"timeStamp"] = @(timeStamp);
- //new core data way!
+ //new coredata way!
[self saveURL:[NSString stringWithFormat:@"%@/%@", [[self.assetWriter.outputURL URLByDeletingLastPathComponent] lastPathComponent], self.assetWriter.outputURL.lastPathComponent] inContext:self.context];
+
+ NSManagedObject *newString = [NSEntityDescription insertNewObjectForEntityForName:@"SegmentEntity" inManagedObjectContext:self.context];
+
+ // Set the value attribute
+ [newString setValue:[NSString stringWithFormat:@"%@/%@", [[self.assetWriter.outputURL URLByDeletingLastPathComponent] lastPathComponent], self.assetWriter.outputURL.lastPathComponent] forKey:@"url"];
+ [newString setValue:@(timeStamp) forKey:@"timeStamp"];
+ [newString setValue:@(CMTimeGetSeconds(time)) forKey:@"duration"];
+ // Save the context
+ if (![self.context save:&error]) {
+ NSLog(@"Failed to save string: %@", error.localizedDescription);
+ } else {
+ NSLog(@"String saved successfully");
+ }
//core data