Skip to content

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

start core data stuff

roryclearb898f28d7756
diff --git a/SegmentsModel.xcdatamodeld/SegmentsModel.xcdatamodel/contents b/SegmentsModel.xcdatamodeld/SegmentsModel.xcdatamodel/contents
new file mode 100644
index 0000000..f667642
--- /dev/null
+++ b/SegmentsModel.xcdatamodeld/SegmentsModel.xcdatamodel/contents
@@ -0,0 +1,6 @@
+<?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="url" optional="YES" attributeType="String"/>
+ </entity>
+</model>
\ No newline at end of file
diff --git a/clearcam.xcodeproj/project.pbxproj b/clearcam.xcodeproj/project.pbxproj
index cec8661..bc69257 100644
--- a/clearcam.xcodeproj/project.pbxproj
+++ b/clearcam.xcodeproj/project.pbxproj
@@ -6,8 +6,13 @@
objectVersion = 77;
objects = {
+/* Begin PBXBuildFile section */
+ BEA6777C2D5CEFE300271B4F /* SegmentsModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = BEA6777A2D5CEFE300271B4F /* SegmentsModel.xcdatamodeld */; };
+/* End PBXBuildFile section */
+
/* Begin PBXFileReference section */
BE007DCA2D2BFF36005D40B3 /* clearcam.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = clearcam.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ BEA6777B2D5CEFE300271B4F /* SegmentsModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = SegmentsModel.xcdatamodel; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
@@ -45,6 +50,7 @@
BE007DC12D2BFF36005D40B3 = {
isa = PBXGroup;
children = (
+ BEA6777A2D5CEFE300271B4F /* SegmentsModel.xcdatamodeld */,
BE007DCC2D2BFF36005D40B3 /* clearcam */,
BE007DCB2D2BFF36005D40B3 /* Products */,
);
@@ -131,6 +137,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ BEA6777C2D5CEFE300271B4F /* SegmentsModel.xcdatamodeld in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -160,6 +167,7 @@
PRODUCT_BUNDLE_IDENTIFIER = roryclear.clearcam;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
+ SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@@ -187,6 +195,7 @@
PRODUCT_BUNDLE_IDENTIFIER = roryclear.clearcam;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
+ SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@@ -329,6 +338,19 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
+
+/* Begin XCVersionGroup section */
+ BEA6777A2D5CEFE300271B4F /* SegmentsModel.xcdatamodeld */ = {
+ isa = XCVersionGroup;
+ children = (
+ BEA6777B2D5CEFE300271B4F /* SegmentsModel.xcdatamodel */,
+ );
+ currentVersion = BEA6777B2D5CEFE300271B4F /* SegmentsModel.xcdatamodel */;
+ path = SegmentsModel.xcdatamodeld;
+ sourceTree = "<group>";
+ versionGroupType = wrapper.xcdatamodel;
+ };
+/* End XCVersionGroup section */
};
rootObject = BE007DC22D2BFF36005D40B3 /* Project object */;
}
diff --git a/clearcam/AppDelegate.h b/clearcam/AppDelegate.h
index c8924bd..5f964eb 100644
--- a/clearcam/AppDelegate.h
+++ b/clearcam/AppDelegate.h
@@ -1,14 +1,11 @@
-//
-// AppDelegate.h
-// clearcam
-//
-// Created by Rory Clear on 06/01/2025.
-//
-
#import <UIKit/UIKit.h>
+#import <CoreData/CoreData.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
+@property (strong, nonatomic) UIWindow *window;
+@property (readonly, strong) NSPersistentContainer *persistentContainer; // Core Data container
-@end
+- (void)saveContext;
+@end
diff --git a/clearcam/AppDelegate.m b/clearcam/AppDelegate.m
index 2e12d0b..589763c 100644
--- a/clearcam/AppDelegate.m
+++ b/clearcam/AppDelegate.m
@@ -1,40 +1,32 @@
-//
-// AppDelegate.m
-// clearcam
-//
-// Created by Rory Clear on 06/01/2025.
-//
-
#import "AppDelegate.h"
@interface AppDelegate ()
-
@end
@implementation AppDelegate
-
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- return YES;
-}
-
-
-#pragma mark - UISceneSession lifecycle
-
-
-- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
- // Called when a new scene session is being created.
- // Use this method to select a configuration to create the new scene with.
- return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
+@synthesize persistentContainer = _persistentContainer;
+
+- (NSPersistentContainer *)persistentContainer {
+ if (_persistentContainer == nil) {
+ _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"SegmentsModel"];
+ [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
+ if (error) {
+ NSLog(@"Unresolved error %@, %@", error, error.userInfo);
+ abort();
+ }
+ }];
+ }
+ return _persistentContainer;
}
-
-- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
- // Called when the user discards a scene session.
- // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
- // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
+- (void)saveContext {
+ NSManagedObjectContext *context = self.persistentContainer.viewContext;
+ NSError *error = nil;
+ if ([context hasChanges] && ![context save:&error]) {
+ NSLog(@"Unresolved error %@, %@", error, error.userInfo);
+ abort();
+ }
}
-
@end
diff --git a/clearcam/ViewController.m b/clearcam/ViewController.m
index 6fe700e..9e81399 100644
--- a/clearcam/ViewController.m
+++ b/clearcam/ViewController.m
@@ -1,6 +1,8 @@
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <Metal/Metal.h>
+#import "AppDelegate.h"
+#import <CoreData/CoreData.h>
#import "Yolo.h"
#import "FileServer.h"
@@ -38,6 +40,18 @@ NSMutableDictionary *classColorMap;
- (void)viewDidLoad {
[super viewDidLoad];
+
+ // coredata stuff
+ AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+ NSManagedObjectContext *context = appDelegate.persistentContainer.viewContext;
+
+ // Save a new string
+ //[self deleteAllSegmentsInContext:context]; to delete all
+ [self saveString:@"Rory here???" inContext:context];
+ // Fetch all saved strings
+ [self fetchAllStringsInContext:context];
+ // coredata stuff
+
self.current_segment_squares = [[NSMutableArray alloc] init];
self.digits = [NSMutableDictionary dictionary];
self.digits[@"0"] = @[@[ @0, @0, @3, @1], @[ @0, @1, @1 , @3], @[ @2, @1, @1 , @3], @[ @0, @4, @3 , @1]];
@@ -132,6 +146,68 @@ NSMutableDictionary *classColorMap;
}
}
+- (void)saveString:(NSString *)string inContext:(NSManagedObjectContext *)context {
+ // Create a new StringEntity object
+ NSManagedObject *newString = [NSEntityDescription insertNewObjectForEntityForName:@"SegmentEntity" inManagedObjectContext:context];
+
+ // Set the value attribute
+ [newString setValue:string forKey:@"url"];
+
+ // Save the context
+ NSError *error = nil;
+ if (![context save:&error]) {
+ NSLog(@"Failed to save string: %@", error.localizedDescription);
+ } else {
+ NSLog(@"String saved successfully");
+ }
+}
+
+- (void)fetchAllStringsInContext:(NSManagedObjectContext *)context {
+ // Create a fetch request for StringEntity
+ NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"SegmentEntity"];
+
+ // Execute the fetch request
+ NSError *error = nil;
+ NSArray *results = [context executeFetchRequest:fetchRequest error:&error];
+
+ if (error) {
+ NSLog(@"Failed to fetch strings: %@", error.localizedDescription);
+ } else {
+ NSLog(@"Fetched strings:");
+ for (NSManagedObject *obj in results) {
+ NSString *value = [obj valueForKey:@"url"];
+ NSLog(@"%@", value);
+ }
+ }
+}
+
+- (void)deleteAllSegmentsInContext:(NSManagedObjectContext *)context {
+ // Create a fetch request for all SegmentEntity objects
+ NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"SegmentEntity"];
+
+ // Fetch all SegmentEntity objects
+ NSError *fetchError = nil;
+ NSArray *segments = [context executeFetchRequest:fetchRequest error:&fetchError];
+
+ if (fetchError) {
+ NSLog(@"Failed to fetch SegmentEntity objects: %@", fetchError.localizedDescription);
+ return;
+ }
+
+ // Loop through all fetched objects and delete them
+ for (NSManagedObject *segment in segments) {
+ [context deleteObject:segment];
+ }
+
+ // Save the context after deletion
+ NSError *saveError = nil;
+ if (![context save:&saveError]) {
+ NSLog(@"Failed to delete objects: %@", saveError.localizedDescription);
+ } else {
+ NSLog(@"All segments deleted successfully");
+ }
+}
+
- (void)setupCamera {
self.captureSession = [[AVCaptureSession alloc] init];
self.captureSession.sessionPreset = AVCaptureSessionPreset1920x1080;