shlist

share and manage lists between multiple people
Log | Files | Refs

commit c8d185611a80494c73be5d4acb3f122fb0e360d0
parent de28786270af19fc41617a480ba5762ebf8147f9
Author: Kyle Milz <kyle@green.krwm.net>
Date:   Mon, 22 Feb 2016 18:50:54 -0700

ios: wip core data

Diffstat:
Mios/shlist.xcodeproj/project.pbxproj | 24++++++++++++++++++++++++
Mios/shlist/AppDelegate.h | 7+++++++
Mios/shlist/AppDelegate.m | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aios/shlist/Images.xcassets/LaunchImage.launchimage/Contents.json | 22++++++++++++++++++++++
Mios/shlist/Info.plist | 2++
Mios/shlist/ListTableViewController.m | 2+-
Mios/shlist/MainTableViewController.m | 2++
Aios/shlist/shlist.xcdatamodeld/shlist.xcdatamodel/contents | 33+++++++++++++++++++++++++++++++++
8 files changed, 190 insertions(+), 1 deletion(-)

diff --git a/ios/shlist.xcodeproj/project.pbxproj b/ios/shlist.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ 27D805731BA2649D00867494 /* ContactsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D805721BA2649D00867494 /* ContactsTableViewController.m */; }; 27D83D2A1BAFC99D0029F54B /* EditTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D83D291BAFC99D0029F54B /* EditTableViewController.m */; }; 27DCC9EB1B9FF89E00207340 /* AddressBook.m in Sources */ = {isa = PBXBuildFile; fileRef = 27DCC9EA1B9FF89E00207340 /* AddressBook.m */; }; + 27E11A141C791FEA00CF03B5 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27E11A131C791FEA00CF03B5 /* CoreData.framework */; }; + 27E11A171C7920BD00CF03B5 /* shlist.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 27E11A151C7920BD00CF03B5 /* shlist.xcdatamodeld */; }; BF7776B91B38928D00526CB0 /* ListTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BF7776B81B38928D00526CB0 /* ListTableViewController.m */; }; /* End PBXBuildFile section */ @@ -68,6 +70,8 @@ 27D83D291BAFC99D0029F54B /* EditTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EditTableViewController.m; sourceTree = "<group>"; }; 27DCC9E91B9FF89E00207340 /* AddressBook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddressBook.h; sourceTree = "<group>"; }; 27DCC9EA1B9FF89E00207340 /* AddressBook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddressBook.m; sourceTree = "<group>"; }; + 27E11A131C791FEA00CF03B5 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; + 27E11A161C7920BD00CF03B5 /* shlist.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = shlist.xcdatamodel; sourceTree = "<group>"; }; BF7776B71B38928D00526CB0 /* ListTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListTableViewController.h; sourceTree = "<group>"; }; BF7776B81B38928D00526CB0 /* ListTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListTableViewController.m; sourceTree = "<group>"; }; /* End PBXFileReference section */ @@ -77,6 +81,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 27E11A141C791FEA00CF03B5 /* CoreData.framework in Frameworks */, 27B03A021B43B8660054B6D2 /* AddressBook.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -94,6 +99,8 @@ 27C70EF61B32AF7F00DADEB3 = { isa = PBXGroup; children = ( + 27E11A151C7920BD00CF03B5 /* shlist.xcdatamodeld */, + 27E11A131C791FEA00CF03B5 /* CoreData.framework */, 27B195B81C45FEE200D7B2E9 /* MsgTypes.h */, 27B03A001B43B8660054B6D2 /* AddressBook.framework */, 27C70F011B32AF8000DADEB3 /* shlist */, @@ -280,6 +287,7 @@ 27C70F2D1B33F3C300DADEB3 /* NewListTableViewController.m in Sources */, 27C70F081B32AF8000DADEB3 /* AppDelegate.m in Sources */, 27DCC9EB1B9FF89E00207340 /* AddressBook.m in Sources */, + 27E11A171C7920BD00CF03B5 /* shlist.xcdatamodeld in Sources */, 27C70F301B33F4FA00DADEB3 /* MainTableViewController.m in Sources */, 27C70F051B32AF8000DADEB3 /* main.m in Sources */, 27D83D2A1BAFC99D0029F54B /* EditTableViewController.m in Sources */, @@ -410,6 +418,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; INFOPLIST_FILE = shlist/Info.plist; @@ -425,6 +434,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; INFOPLIST_FILE = shlist/Info.plist; @@ -501,6 +511,20 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + 27E11A151C7920BD00CF03B5 /* shlist.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + 27E11A161C7920BD00CF03B5 /* shlist.xcdatamodel */, + ); + currentVersion = 27E11A161C7920BD00CF03B5 /* shlist.xcdatamodel */; + name = shlist.xcdatamodeld; + path = shlist/shlist.xcdatamodeld; + sourceTree = "<group>"; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ }; rootObject = 27C70EF71B32AF7F00DADEB3 /* Project object */; } diff --git a/ios/shlist/AppDelegate.h b/ios/shlist/AppDelegate.h @@ -4,4 +4,11 @@ @property (strong, nonatomic) UIWindow *window; +@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; +@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; +@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; + +- (void)saveContext; +- (NSURL *)applicationDocumentsDirectory; + @end diff --git a/ios/shlist/AppDelegate.m b/ios/shlist/AppDelegate.m @@ -1,6 +1,8 @@ #import "AppDelegate.h" #import "Network.h" +#import <CoreData/CoreData.h> + @interface AppDelegate () { Network *network_connection; } @@ -9,6 +11,9 @@ @implementation AppDelegate +@synthesize managedObjectContext = _managedObjectContext; +@synthesize managedObjectModel = _managedObjectModel; +@synthesize persistentStoreCoordinator = _persistentStoreCoordinator; - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { @@ -125,4 +130,98 @@ NSLog(@"Error in registration. Error: %@", err); } +- (void)saveContext +{ + NSError *error = nil; + NSManagedObjectContext *managedObjectContext = self.managedObjectContext; + if (managedObjectContext != nil) { + if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { + // Replace this implementation with code to handle the error appropriately. + // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + NSLog(@"Unresolved error %@, %@", error, [error userInfo]); + abort(); + } + } +} + +#pragma mark - Core Data stack + +// Returns the managed object context for the application. +// If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application. +- (NSManagedObjectContext *)managedObjectContext +{ + if (_managedObjectContext != nil) { + return _managedObjectContext; + } + + NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; + if (coordinator != nil) { + _managedObjectContext = [[NSManagedObjectContext alloc] init]; + [_managedObjectContext setPersistentStoreCoordinator:coordinator]; + } + return _managedObjectContext; +} + +// Returns the managed object model for the application. +// If the model doesn't already exist, it is created from the application's model. +- (NSManagedObjectModel *)managedObjectModel +{ + if (_managedObjectModel != nil) { + return _managedObjectModel; + } + NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"shlist" withExtension:@"momd"]; + _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; + return _managedObjectModel; +} + +// Returns the persistent store coordinator for the application. +// If the coordinator doesn't already exist, it is created and the application's store added to it. +- (NSPersistentStoreCoordinator *)persistentStoreCoordinator +{ + if (_persistentStoreCoordinator != nil) { + return _persistentStoreCoordinator; + } + + NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"shlist.sqlite"]; + + NSError *error = nil; + _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; + if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { + /* + Replace this implementation with code to handle the error appropriately. + + abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + + Typical reasons for an error here include: + * The persistent store is not accessible; + * The schema for the persistent store is incompatible with current managed object model. + Check the error message to determine what the actual problem was. + + If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory. + + If you encounter schema incompatibility errors during development, you can reduce their frequency by: + * Simply deleting the existing store: + [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil] + + * Performing automatic lightweight migration by passing the following dictionary as the options parameter: + @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} + + Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details. + + */ + NSLog(@"Unresolved error %@, %@", error, [error userInfo]); + abort(); + } + + return _persistentStoreCoordinator; +} + +#pragma mark - Application's Documents directory + +// Returns the URL to the application's Documents directory. +- (NSURL *)applicationDocumentsDirectory +{ + return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; +} + @end \ No newline at end of file diff --git a/ios/shlist/Images.xcassets/LaunchImage.launchimage/Contents.json b/ios/shlist/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "orientation" : "portrait", + "idiom" : "iphone", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "minimum-system-version" : "7.0", + "subtype" : "retina4", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} +\ No newline at end of file diff --git a/ios/shlist/Info.plist b/ios/shlist/Info.plist @@ -30,6 +30,8 @@ <array> <string>armv7</string> </array> + <key>UIStatusBarHidden</key> + <false/> <key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> diff --git a/ios/shlist/ListTableViewController.m b/ios/shlist/ListTableViewController.m @@ -129,7 +129,7 @@ { // XXX: This is an iOS 7+ hack only! // http://stackoverflow.com/questions/13014592/how-to-get-indexpath-over-touched-button - UITableViewCell *cell = [(UITableViewCell *)[[sender superview] superview] superview]; + UITableViewCell *cell = (UITableViewCell *)[[[sender superview] superview] superview]; NSIndexPath *path = [self.tableView indexPathForCell:cell]; ListItem *item = [_list_items objectAtIndex:[path row]]; diff --git a/ios/shlist/MainTableViewController.m b/ios/shlist/MainTableViewController.m @@ -40,8 +40,10 @@ [default_center addObserver:self selector:@selector(push_friend_added_list:) name:@"PushNotification_friend_added_list" object:nil]; + /* [default_center addObserver:self selector:@selector(push_updated_list:) name:@"PushNotification_updated_list" object:nil]; + */ const SEL selectors[] = { @selector(lists_get_finished:), diff --git a/ios/shlist/shlist.xcdatamodeld/shlist.xcdatamodel/contents b/ios/shlist/shlist.xcdatamodeld/shlist.xcdatamodel/contents @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="7701" systemVersion="14F1605" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic"> + <entity name="Contacts" syncable="YES"> + <attribute name="contact" optional="YES" attributeType="String" syncable="YES"/> + <attribute name="selected" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/> + </entity> + <entity name="ListItems" syncable="YES"> + <attribute name="last_updated" optional="YES" attributeType="Date" syncable="YES"/> + <attribute name="list_num" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/> + <attribute name="name" optional="YES" attributeType="String" syncable="YES"/> + <attribute name="num" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/> + <attribute name="owner" optional="YES" attributeType="String" syncable="YES"/> + <attribute name="quantity" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/> + <attribute name="status" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/> + <relationship name="relationship" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="SharedLists" inverseName="relationship" inverseEntity="SharedLists" syncable="YES"/> + </entity> + <entity name="SharedLists" syncable="YES"> + <attribute name="date" optional="YES" attributeType="Date" syncable="YES"/> + <attribute name="items_complete" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/> + <attribute name="items_total" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/> + <attribute name="last_updated" optional="YES" attributeType="Date" syncable="YES"/> + <attribute name="name" optional="YES" attributeType="String" syncable="YES"/> + <attribute name="num" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/> + <attribute name="num_members" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/> + <relationship name="relationship" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="ListItems" inverseName="relationship" inverseEntity="ListItems" syncable="YES"/> + </entity> + <elements> + <element name="Contacts" positionX="126" positionY="-54" width="128" height="73"/> + <element name="SharedLists" positionX="-54" positionY="9" width="128" height="163"/> + <element name="ListItems" positionX="135" positionY="126" width="128" height="163"/> + </elements> +</model> +\ No newline at end of file