From 6f28affa08a240d3b1f4bc9af20d80eceb9e2e03 Mon Sep 17 00:00:00 2001 From: "Mike Enriquez mike@enriquez.me" Date: Wed, 13 Feb 2013 20:31:10 -0500 Subject: [PATCH] FIRST --- .gitignore | 8 + CheckMateShopper.xcodeproj/project.pbxproj | 392 ++++++++++++++++++ CheckMateShopper/CMAppDelegate.h | 22 + CheckMateShopper/CMAppDelegate.m | 145 +++++++ CheckMateShopper/CheckMateShopper-Info.plist | 47 +++ CheckMateShopper/CheckMateShopper-Prefix.pch | 19 + .../.xccurrentversion | 8 + .../CheckMateShopper.xcdatamodel/contents | 16 + .../Controllers/CMEditItemViewController.h | 19 + .../Controllers/CMEditItemViewController.m | 69 +++ .../Controllers/CMItemListViewController.h | 14 + .../Controllers/CMItemListViewController.m | 208 ++++++++++ .../Controllers/CMNewItemViewController.h | 17 + .../Controllers/CMNewItemViewController.m | 48 +++ CheckMateShopper/Default-568h@2x.png | Bin 0 -> 18594 bytes CheckMateShopper/Default.png | Bin 0 -> 6540 bytes CheckMateShopper/Default@2x.png | Bin 0 -> 16107 bytes CheckMateShopper/Models/CMCategory.h | 35 ++ CheckMateShopper/Models/CMCategory.m | 62 +++ CheckMateShopper/Models/CMItem.h | 23 + CheckMateShopper/Models/CMItem.m | 53 +++ CheckMateShopper/Storyboard.storyboard | 254 ++++++++++++ .../CMShopperHTTPClient/CMShopperHTTPClient.h | 20 + .../CMShopperHTTPClient/CMShopperHTTPClient.m | 124 ++++++ CheckMateShopper/en.lproj/InfoPlist.strings | 2 + CheckMateShopper/main.m | 18 + README.md | 12 + 27 files changed, 1635 insertions(+) create mode 100644 .gitignore create mode 100644 CheckMateShopper.xcodeproj/project.pbxproj create mode 100644 CheckMateShopper/CMAppDelegate.h create mode 100644 CheckMateShopper/CMAppDelegate.m create mode 100644 CheckMateShopper/CheckMateShopper-Info.plist create mode 100644 CheckMateShopper/CheckMateShopper-Prefix.pch create mode 100644 CheckMateShopper/CheckMateShopper.xcdatamodeld/.xccurrentversion create mode 100644 CheckMateShopper/CheckMateShopper.xcdatamodeld/CheckMateShopper.xcdatamodel/contents create mode 100644 CheckMateShopper/Controllers/CMEditItemViewController.h create mode 100644 CheckMateShopper/Controllers/CMEditItemViewController.m create mode 100644 CheckMateShopper/Controllers/CMItemListViewController.h create mode 100644 CheckMateShopper/Controllers/CMItemListViewController.m create mode 100644 CheckMateShopper/Controllers/CMNewItemViewController.h create mode 100644 CheckMateShopper/Controllers/CMNewItemViewController.m create mode 100644 CheckMateShopper/Default-568h@2x.png create mode 100644 CheckMateShopper/Default.png create mode 100644 CheckMateShopper/Default@2x.png create mode 100644 CheckMateShopper/Models/CMCategory.h create mode 100644 CheckMateShopper/Models/CMCategory.m create mode 100644 CheckMateShopper/Models/CMItem.h create mode 100644 CheckMateShopper/Models/CMItem.m create mode 100644 CheckMateShopper/Storyboard.storyboard create mode 100644 CheckMateShopper/Vendor/CMShopperHTTPClient/CMShopperHTTPClient.h create mode 100644 CheckMateShopper/Vendor/CMShopperHTTPClient/CMShopperHTTPClient.m create mode 100644 CheckMateShopper/en.lproj/InfoPlist.strings create mode 100644 CheckMateShopper/main.m create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cbfa191 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.mode1 +*.mode1v3 +*.mode2v3 +*.perspective +*.perspectivev3 +*.pbxuser +*.xcodeproj/project.xcworkspace/ +*.xcodeproj/xcuserdata/ diff --git a/CheckMateShopper.xcodeproj/project.pbxproj b/CheckMateShopper.xcodeproj/project.pbxproj new file mode 100644 index 0000000..3d8c510 --- /dev/null +++ b/CheckMateShopper.xcodeproj/project.pbxproj @@ -0,0 +1,392 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 051CD39816CC114900D9022C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051CD39716CC114900D9022C /* UIKit.framework */; }; + 051CD39A16CC114900D9022C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051CD39916CC114900D9022C /* Foundation.framework */; }; + 051CD39C16CC114900D9022C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051CD39B16CC114900D9022C /* CoreGraphics.framework */; }; + 051CD39E16CC114900D9022C /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 051CD39D16CC114900D9022C /* CoreData.framework */; }; + 051CD3A416CC114900D9022C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 051CD3A216CC114900D9022C /* InfoPlist.strings */; }; + 051CD3A616CC114900D9022C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 051CD3A516CC114900D9022C /* main.m */; }; + 051CD3AA16CC114A00D9022C /* CMAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 051CD3A916CC114A00D9022C /* CMAppDelegate.m */; }; + 051CD3AC16CC114A00D9022C /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 051CD3AB16CC114A00D9022C /* Default.png */; }; + 051CD3AE16CC114A00D9022C /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 051CD3AD16CC114A00D9022C /* Default@2x.png */; }; + 051CD3B016CC114A00D9022C /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 051CD3AF16CC114A00D9022C /* Default-568h@2x.png */; }; + 051CD3B316CC114A00D9022C /* CheckMateShopper.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 051CD3B116CC114A00D9022C /* CheckMateShopper.xcdatamodeld */; }; + 051CD3C316CC135200D9022C /* CMShopperHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 051CD3C216CC135200D9022C /* CMShopperHTTPClient.m */; }; + 051CD3C816CC13F600D9022C /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 051CD3C716CC13F600D9022C /* Storyboard.storyboard */; }; + 051CD3D416CC214800D9022C /* CMNewItemViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 051CD3D316CC214800D9022C /* CMNewItemViewController.m */; }; + 05FD91B216CC295C007646DE /* CMItemListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 05FD91B116CC295C007646DE /* CMItemListViewController.m */; }; + 05FD91B816CC33A1007646DE /* CMItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 05FD91B716CC33A1007646DE /* CMItem.m */; }; + 05FD91C416CC38CF007646DE /* CMCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 05FD91C316CC38CF007646DE /* CMCategory.m */; }; + 05FD91C716CC4BE9007646DE /* CMEditItemViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 05FD91C616CC4BE9007646DE /* CMEditItemViewController.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 051CD39416CC114900D9022C /* CheckMateShopper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CheckMateShopper.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 051CD39716CC114900D9022C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 051CD39916CC114900D9022C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 051CD39B16CC114900D9022C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + 051CD39D16CC114900D9022C /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; + 051CD3A116CC114900D9022C /* CheckMateShopper-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CheckMateShopper-Info.plist"; sourceTree = ""; }; + 051CD3A316CC114900D9022C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 051CD3A516CC114900D9022C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 051CD3A716CC114900D9022C /* CheckMateShopper-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CheckMateShopper-Prefix.pch"; sourceTree = ""; }; + 051CD3A816CC114900D9022C /* CMAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CMAppDelegate.h; sourceTree = ""; }; + 051CD3A916CC114A00D9022C /* CMAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CMAppDelegate.m; sourceTree = ""; }; + 051CD3AB16CC114A00D9022C /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; + 051CD3AD16CC114A00D9022C /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; + 051CD3AF16CC114A00D9022C /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; + 051CD3B216CC114A00D9022C /* CheckMateShopper.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CheckMateShopper.xcdatamodel; sourceTree = ""; }; + 051CD3C116CC135200D9022C /* CMShopperHTTPClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CMShopperHTTPClient.h; path = Vendor/CMShopperHTTPClient/CMShopperHTTPClient.h; sourceTree = ""; }; + 051CD3C216CC135200D9022C /* CMShopperHTTPClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CMShopperHTTPClient.m; path = Vendor/CMShopperHTTPClient/CMShopperHTTPClient.m; sourceTree = ""; }; + 051CD3C716CC13F600D9022C /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = ""; }; + 051CD3D216CC214800D9022C /* CMNewItemViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CMNewItemViewController.h; path = Controllers/CMNewItemViewController.h; sourceTree = ""; }; + 051CD3D316CC214800D9022C /* CMNewItemViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CMNewItemViewController.m; path = Controllers/CMNewItemViewController.m; sourceTree = ""; }; + 05FD91B016CC295C007646DE /* CMItemListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CMItemListViewController.h; path = Controllers/CMItemListViewController.h; sourceTree = ""; }; + 05FD91B116CC295C007646DE /* CMItemListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CMItemListViewController.m; path = Controllers/CMItemListViewController.m; sourceTree = ""; }; + 05FD91B616CC33A1007646DE /* CMItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CMItem.h; path = Models/CMItem.h; sourceTree = ""; }; + 05FD91B716CC33A1007646DE /* CMItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CMItem.m; path = Models/CMItem.m; sourceTree = ""; }; + 05FD91C216CC38CF007646DE /* CMCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CMCategory.h; path = Models/CMCategory.h; sourceTree = ""; }; + 05FD91C316CC38CF007646DE /* CMCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CMCategory.m; path = Models/CMCategory.m; sourceTree = ""; }; + 05FD91C516CC4BE9007646DE /* CMEditItemViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CMEditItemViewController.h; path = Controllers/CMEditItemViewController.h; sourceTree = ""; }; + 05FD91C616CC4BE9007646DE /* CMEditItemViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CMEditItemViewController.m; path = Controllers/CMEditItemViewController.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 051CD39116CC114900D9022C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 051CD39816CC114900D9022C /* UIKit.framework in Frameworks */, + 051CD39A16CC114900D9022C /* Foundation.framework in Frameworks */, + 051CD39C16CC114900D9022C /* CoreGraphics.framework in Frameworks */, + 051CD39E16CC114900D9022C /* CoreData.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 051CD38B16CC114900D9022C = { + isa = PBXGroup; + children = ( + 051CD39F16CC114900D9022C /* CheckMateShopper */, + 051CD39616CC114900D9022C /* Frameworks */, + 051CD39516CC114900D9022C /* Products */, + ); + sourceTree = ""; + }; + 051CD39516CC114900D9022C /* Products */ = { + isa = PBXGroup; + children = ( + 051CD39416CC114900D9022C /* CheckMateShopper.app */, + ); + name = Products; + sourceTree = ""; + }; + 051CD39616CC114900D9022C /* Frameworks */ = { + isa = PBXGroup; + children = ( + 051CD39716CC114900D9022C /* UIKit.framework */, + 051CD39916CC114900D9022C /* Foundation.framework */, + 051CD39B16CC114900D9022C /* CoreGraphics.framework */, + 051CD39D16CC114900D9022C /* CoreData.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 051CD39F16CC114900D9022C /* CheckMateShopper */ = { + isa = PBXGroup; + children = ( + 051CD3B116CC114A00D9022C /* CheckMateShopper.xcdatamodeld */, + 051CD3A816CC114900D9022C /* CMAppDelegate.h */, + 051CD3A916CC114A00D9022C /* CMAppDelegate.m */, + 051CD3BB16CC11E700D9022C /* Controllers */, + 051CD3B916CC11DA00D9022C /* Models */, + 051CD3C716CC13F600D9022C /* Storyboard.storyboard */, + 051CD3A016CC114900D9022C /* Supporting Files */, + 051CD3BF16CC133000D9022C /* Vendor */, + 051CD3BA16CC11DE00D9022C /* Views */, + ); + path = CheckMateShopper; + sourceTree = ""; + }; + 051CD3A016CC114900D9022C /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 051CD3A116CC114900D9022C /* CheckMateShopper-Info.plist */, + 051CD3A216CC114900D9022C /* InfoPlist.strings */, + 051CD3A516CC114900D9022C /* main.m */, + 051CD3A716CC114900D9022C /* CheckMateShopper-Prefix.pch */, + 051CD3AB16CC114A00D9022C /* Default.png */, + 051CD3AD16CC114A00D9022C /* Default@2x.png */, + 051CD3AF16CC114A00D9022C /* Default-568h@2x.png */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 051CD3B916CC11DA00D9022C /* Models */ = { + isa = PBXGroup; + children = ( + 05FD91C216CC38CF007646DE /* CMCategory.h */, + 05FD91C316CC38CF007646DE /* CMCategory.m */, + 05FD91B616CC33A1007646DE /* CMItem.h */, + 05FD91B716CC33A1007646DE /* CMItem.m */, + ); + name = Models; + sourceTree = ""; + }; + 051CD3BA16CC11DE00D9022C /* Views */ = { + isa = PBXGroup; + children = ( + ); + name = Views; + sourceTree = ""; + }; + 051CD3BB16CC11E700D9022C /* Controllers */ = { + isa = PBXGroup; + children = ( + 05FD91C516CC4BE9007646DE /* CMEditItemViewController.h */, + 05FD91C616CC4BE9007646DE /* CMEditItemViewController.m */, + 05FD91B016CC295C007646DE /* CMItemListViewController.h */, + 05FD91B116CC295C007646DE /* CMItemListViewController.m */, + 051CD3D216CC214800D9022C /* CMNewItemViewController.h */, + 051CD3D316CC214800D9022C /* CMNewItemViewController.m */, + ); + name = Controllers; + sourceTree = ""; + }; + 051CD3BF16CC133000D9022C /* Vendor */ = { + isa = PBXGroup; + children = ( + 051CD3C016CC133500D9022C /* CMShopperHTTPClient */, + ); + name = Vendor; + sourceTree = ""; + }; + 051CD3C016CC133500D9022C /* CMShopperHTTPClient */ = { + isa = PBXGroup; + children = ( + 051CD3C116CC135200D9022C /* CMShopperHTTPClient.h */, + 051CD3C216CC135200D9022C /* CMShopperHTTPClient.m */, + ); + name = CMShopperHTTPClient; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 051CD39316CC114900D9022C /* CheckMateShopper */ = { + isa = PBXNativeTarget; + buildConfigurationList = 051CD3B616CC114A00D9022C /* Build configuration list for PBXNativeTarget "CheckMateShopper" */; + buildPhases = ( + 051CD39016CC114900D9022C /* Sources */, + 051CD39116CC114900D9022C /* Frameworks */, + 051CD39216CC114900D9022C /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = CheckMateShopper; + productName = CheckMateShopper; + productReference = 051CD39416CC114900D9022C /* CheckMateShopper.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 051CD38C16CC114900D9022C /* Project object */ = { + isa = PBXProject; + attributes = { + CLASSPREFIX = CM; + LastUpgradeCheck = 0460; + ORGANIZATIONNAME = "Mike Enriquez"; + }; + buildConfigurationList = 051CD38F16CC114900D9022C /* Build configuration list for PBXProject "CheckMateShopper" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 051CD38B16CC114900D9022C; + productRefGroup = 051CD39516CC114900D9022C /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 051CD39316CC114900D9022C /* CheckMateShopper */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 051CD39216CC114900D9022C /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 051CD3A416CC114900D9022C /* InfoPlist.strings in Resources */, + 051CD3AC16CC114A00D9022C /* Default.png in Resources */, + 051CD3AE16CC114A00D9022C /* Default@2x.png in Resources */, + 051CD3B016CC114A00D9022C /* Default-568h@2x.png in Resources */, + 051CD3C816CC13F600D9022C /* Storyboard.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 051CD39016CC114900D9022C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 051CD3A616CC114900D9022C /* main.m in Sources */, + 051CD3AA16CC114A00D9022C /* CMAppDelegate.m in Sources */, + 051CD3B316CC114A00D9022C /* CheckMateShopper.xcdatamodeld in Sources */, + 051CD3C316CC135200D9022C /* CMShopperHTTPClient.m in Sources */, + 051CD3D416CC214800D9022C /* CMNewItemViewController.m in Sources */, + 05FD91B216CC295C007646DE /* CMItemListViewController.m in Sources */, + 05FD91B816CC33A1007646DE /* CMItem.m in Sources */, + 05FD91C416CC38CF007646DE /* CMCategory.m in Sources */, + 05FD91C716CC4BE9007646DE /* CMEditItemViewController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 051CD3A216CC114900D9022C /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 051CD3A316CC114900D9022C /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 051CD3B416CC114A00D9022C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 6.1; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 051CD3B516CC114A00D9022C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 6.1; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 051CD3B716CC114A00D9022C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "CheckMateShopper/CheckMateShopper-Prefix.pch"; + INFOPLIST_FILE = "CheckMateShopper/CheckMateShopper-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + 051CD3B816CC114A00D9022C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "CheckMateShopper/CheckMateShopper-Prefix.pch"; + INFOPLIST_FILE = "CheckMateShopper/CheckMateShopper-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 051CD38F16CC114900D9022C /* Build configuration list for PBXProject "CheckMateShopper" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 051CD3B416CC114A00D9022C /* Debug */, + 051CD3B516CC114A00D9022C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 051CD3B616CC114A00D9022C /* Build configuration list for PBXNativeTarget "CheckMateShopper" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 051CD3B716CC114A00D9022C /* Debug */, + 051CD3B816CC114A00D9022C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + 051CD3B116CC114A00D9022C /* CheckMateShopper.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + 051CD3B216CC114A00D9022C /* CheckMateShopper.xcdatamodel */, + ); + currentVersion = 051CD3B216CC114A00D9022C /* CheckMateShopper.xcdatamodel */; + path = CheckMateShopper.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ + }; + rootObject = 051CD38C16CC114900D9022C /* Project object */; +} diff --git a/CheckMateShopper/CMAppDelegate.h b/CheckMateShopper/CMAppDelegate.h new file mode 100644 index 0000000..83ca693 --- /dev/null +++ b/CheckMateShopper/CMAppDelegate.h @@ -0,0 +1,22 @@ +// +// CMAppDelegate.h +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import + +@interface CMAppDelegate : UIResponder + +@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/CheckMateShopper/CMAppDelegate.m b/CheckMateShopper/CMAppDelegate.m new file mode 100644 index 0000000..1035fbd --- /dev/null +++ b/CheckMateShopper/CMAppDelegate.m @@ -0,0 +1,145 @@ +// +// CMAppDelegate.m +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import "CMAppDelegate.h" + +@implementation CMAppDelegate + +@synthesize managedObjectContext = _managedObjectContext; +@synthesize managedObjectModel = _managedObjectModel; +@synthesize persistentStoreCoordinator = _persistentStoreCoordinator; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + // Saves changes in the application's managed object context before the application terminates. + [self saveContext]; +} + +- (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:@"CheckMateShopper" 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:@"CheckMateShopper.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 diff --git a/CheckMateShopper/CheckMateShopper-Info.plist b/CheckMateShopper/CheckMateShopper-Info.plist new file mode 100644 index 0000000..6c43758 --- /dev/null +++ b/CheckMateShopper/CheckMateShopper-Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.mikeenriquez.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIMainStoryboardFile + Storyboard + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/CheckMateShopper/CheckMateShopper-Prefix.pch b/CheckMateShopper/CheckMateShopper-Prefix.pch new file mode 100644 index 0000000..47fcb47 --- /dev/null +++ b/CheckMateShopper/CheckMateShopper-Prefix.pch @@ -0,0 +1,19 @@ +// +// Prefix header for all source files of the 'CheckMateShopper' target in the 'CheckMateShopper' project +// + +#import + +#ifndef __IPHONE_3_0 +#warning "This project uses features only available in iOS SDK 3.0 and later." +#endif + +#ifdef __OBJC__ + #import + #import + #import +#endif + +#import "CMCategory.h" +#import "CMItem.h" +#import "CMShopperHTTPClient.h" \ No newline at end of file diff --git a/CheckMateShopper/CheckMateShopper.xcdatamodeld/.xccurrentversion b/CheckMateShopper/CheckMateShopper.xcdatamodeld/.xccurrentversion new file mode 100644 index 0000000..7dbe98e --- /dev/null +++ b/CheckMateShopper/CheckMateShopper.xcdatamodeld/.xccurrentversion @@ -0,0 +1,8 @@ + + + + + _XCCurrentVersionName + CheckMateShopper.xcdatamodel + + diff --git a/CheckMateShopper/CheckMateShopper.xcdatamodeld/CheckMateShopper.xcdatamodel/contents b/CheckMateShopper/CheckMateShopper.xcdatamodeld/CheckMateShopper.xcdatamodel/contents new file mode 100644 index 0000000..86af90e --- /dev/null +++ b/CheckMateShopper/CheckMateShopper.xcdatamodeld/CheckMateShopper.xcdatamodel/contents @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CheckMateShopper/Controllers/CMEditItemViewController.h b/CheckMateShopper/Controllers/CMEditItemViewController.h new file mode 100644 index 0000000..d0a5820 --- /dev/null +++ b/CheckMateShopper/Controllers/CMEditItemViewController.h @@ -0,0 +1,19 @@ +// +// CMEditItemViewController.h +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import + +@interface CMEditItemViewController : UIViewController +- (IBAction)save:(id)sender; +- (IBAction)cancel:(id)sender; +- (IBAction)deleteItem:(id)sender; +@property (weak, nonatomic) IBOutlet UITextField *nameTextField; +@property (weak, nonatomic) IBOutlet UITextField *categoryTextField; +@property (strong, nonatomic) NSManagedObjectContext *context; +@property (strong, nonatomic) CMItem *item; +@end diff --git a/CheckMateShopper/Controllers/CMEditItemViewController.m b/CheckMateShopper/Controllers/CMEditItemViewController.m new file mode 100644 index 0000000..e3bf36a --- /dev/null +++ b/CheckMateShopper/Controllers/CMEditItemViewController.m @@ -0,0 +1,69 @@ +// +// CMEditItemViewController.m +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import "CMEditItemViewController.h" + +@interface CMEditItemViewController () + +@end + +@implementation CMEditItemViewController + +#pragma mark UIVIewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + self.nameTextField.text = self.item.name; + self.categoryTextField.text = ((CMCategory *)self.item.category).name; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + _context = nil; + _item = nil; +} + +#pragma mark IBActions + +- (IBAction)save:(id)sender { + NSString *itemName = self.nameTextField.text; + NSString *categoryName = self.categoryTextField.text; + + if (itemName.length > 0 && categoryName.length > 0) { + CMShopperHTTPClient *httpClient = [CMShopperHTTPClient sharedInstance]; + [httpClient updateItemWithId:self.item.itemId name:itemName category:categoryName onComplete:^(NSDictionary *item, NSError *error) { + if (error) { + NSLog(@"TODO: alert"); + } else { + [self.context deleteObject:self.item]; + [self dismissViewControllerAnimated:YES completion:nil]; + } + }]; + } else { + NSLog(@"TODO: alert"); + } +} + +- (IBAction)cancel:(id)sender { + [self dismissViewControllerAnimated:YES completion:nil]; +} + +- (IBAction)deleteItem:(id)sender { + CMShopperHTTPClient *httpClient = [CMShopperHTTPClient sharedInstance]; + [httpClient deleteItemWithId:self.item.itemId onComplete:^(NSError *error) { + if (error) { + NSLog(@"TODO: alert"); + } else { + [self.context deleteObject:self.item]; + [self dismissViewControllerAnimated:YES completion:nil]; + } + }]; +} +@end diff --git a/CheckMateShopper/Controllers/CMItemListViewController.h b/CheckMateShopper/Controllers/CMItemListViewController.h new file mode 100644 index 0000000..3574894 --- /dev/null +++ b/CheckMateShopper/Controllers/CMItemListViewController.h @@ -0,0 +1,14 @@ +// +// CMItemListViewController.h +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import + +@interface CMItemListViewController : UITableViewController +@property (strong, nonatomic) IBOutlet UITableView *table; +@property (strong, nonatomic) NSManagedObjectContext *context; +@end diff --git a/CheckMateShopper/Controllers/CMItemListViewController.m b/CheckMateShopper/Controllers/CMItemListViewController.m new file mode 100644 index 0000000..6d87aea --- /dev/null +++ b/CheckMateShopper/Controllers/CMItemListViewController.m @@ -0,0 +1,208 @@ +// +// CMItemListViewController.m +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import "CMItemListViewController.h" +#import "CMNewItemViewController.h" +#import "CMEditItemViewController.h" +#import "CMAppDelegate.h" + +@interface CMItemListViewController () +@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController; +- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath; +- (void)synchronizeWithServerOnComplete:(void(^)(NSError *error))completeBlock; +@end + +@implementation CMItemListViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; + [refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged]; + [self.table addSubview:refreshControl]; + + self.context = ((CMAppDelegate *)[UIApplication sharedApplication].delegate).managedObjectContext; + [self.fetchedResultsController performFetch:nil]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + [self synchronizeWithServerOnComplete:nil]; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + + _table = nil; + _context = nil; + _fetchedResultsController = nil; +} + +#pragma mark - Properties + +- (NSFetchedResultsController *)fetchedResultsController { + if (_fetchedResultsController) return _fetchedResultsController; + + NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; + fetchRequest.entity = [NSEntityDescription entityForName:@"CMItem" inManagedObjectContext:self.context]; + fetchRequest.fetchBatchSize = 30; + fetchRequest.sortDescriptors = [NSArray arrayWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"category.name" ascending:YES], [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES], nil]; + + _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest + managedObjectContext:self.context + sectionNameKeyPath:@"category.name" + cacheName:nil]; + _fetchedResultsController.delegate = self; + + return _fetchedResultsController; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + NSArray *sections = [self.fetchedResultsController sections]; + return sections.count; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + NSArray *sections = [self.fetchedResultsController sections]; + id sectionInfo = [sections objectAtIndex:section]; + return sectionInfo.numberOfObjects; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *CellIdentifier = @"ItemCell"; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; + + [self configureCell:cell atIndexPath:indexPath]; + + return cell; +} + +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section +{ + NSArray *sections = [self.fetchedResultsController sections]; + id sectionInfo = [sections objectAtIndex:section]; + return sectionInfo.name; +} + +#pragma mark - NSFetchedResultsControllerDelegate + +- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller +{ + [self.table beginUpdates]; +} + +- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath +{ + + UITableView *tableView = self.table; + + switch(type) { + + case NSFetchedResultsChangeInsert: + [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone]; + break; + + case NSFetchedResultsChangeDelete: + [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; + break; + + case NSFetchedResultsChangeUpdate: + [self configureCell:(UITableViewCell *)[self.table cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; + break; + } +} + +- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id )sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type +{ + switch(type) { + + case NSFetchedResultsChangeInsert: + [self.table insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationNone]; + break; + + case NSFetchedResultsChangeDelete: + [self.table deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationNone]; + break; + } +} + +- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller +{ + [self.table endUpdates]; + [self.table reloadData]; +} + +#pragma mark - UIViewController + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + [self performSelector:NSSelectorFromString(segue.identifier) withObject:segue.destinationViewController]; +#pragma clang diagnostic pop +} + +#pragma mark - Prepare for segue methods + +- (void)prepareNewItemViewController:(CMNewItemViewController *)newItemViewController +{ + newItemViewController.context = self.context; +} + +- (void)prepareEditItemViewController:(CMEditItemViewController *)editItemViewController +{ + CMItem *item = (CMItem *)[self.fetchedResultsController objectAtIndexPath:[self.table indexPathForSelectedRow]]; + editItemViewController.item = item; + editItemViewController.context = self.context; +} + +#pragma mark - Private + +- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath +{ + CMItem *item = (CMItem *)[self.fetchedResultsController objectAtIndexPath:indexPath]; + cell.textLabel.text = item.name; +} + +- (void)synchronizeWithServerOnComplete:(void(^)(NSError *error))completeBlock; +{ + CMShopperHTTPClient *httpClient = [CMShopperHTTPClient sharedInstance]; + [httpClient listItemsOnComplete:^(NSArray *items, NSError *error) { + if (error) { + NSLog(@"TODO: alert"); + } else { + for (NSDictionary *itemJson in items) { + NSString *itemId = [itemJson objectForKey:@"id"]; + CMItem *item = [CMItem findOrBuildById:itemId inContext:self.context]; + [item unpackDictionary:itemJson inContext:self.context]; + } + + [self.context save:nil]; + [self.fetchedResultsController performFetch:nil]; + } + + if (completeBlock) completeBlock(error); + }]; +} + +- (void)handleRefresh:(UIRefreshControl *)refreshControl +{ + [self synchronizeWithServerOnComplete:^(NSError *error) { + [refreshControl endRefreshing]; + }]; +} + +@end diff --git a/CheckMateShopper/Controllers/CMNewItemViewController.h b/CheckMateShopper/Controllers/CMNewItemViewController.h new file mode 100644 index 0000000..5317bbf --- /dev/null +++ b/CheckMateShopper/Controllers/CMNewItemViewController.h @@ -0,0 +1,17 @@ +// +// CMNewItemViewController.h +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import + +@interface CMNewItemViewController : UIViewController +@property (strong, nonatomic) NSManagedObjectContext *context; +@property (weak, nonatomic) IBOutlet UITextField *nameTextField; +@property (weak, nonatomic) IBOutlet UITextField *categoryTextField; +- (IBAction)save:(id)sender; +- (IBAction)cancel:(id)sender; +@end diff --git a/CheckMateShopper/Controllers/CMNewItemViewController.m b/CheckMateShopper/Controllers/CMNewItemViewController.m new file mode 100644 index 0000000..0f33470 --- /dev/null +++ b/CheckMateShopper/Controllers/CMNewItemViewController.m @@ -0,0 +1,48 @@ +// +// CMNewItemViewController.m +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import "CMNewItemViewController.h" + +@interface CMNewItemViewController () + +@end + +@implementation CMNewItemViewController + +#pragma mark UIVIewController + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + _context = nil; +} + +#pragma mark IBActions + +- (IBAction)save:(id)sender { + NSString *itemName = self.nameTextField.text; + NSString *categoryName = self.categoryTextField.text; + + if (itemName.length > 0 && categoryName.length > 0) { + CMShopperHTTPClient *httpClient = [CMShopperHTTPClient sharedInstance]; + [httpClient createItemWithName:itemName category:categoryName onComplete:^(NSDictionary *item, NSError *error) { + if (error) { + NSLog(@"TODO: alert"); + } else { + [self dismissViewControllerAnimated:YES completion:nil]; + } + }]; + } else { + NSLog(@"TODO: alert"); + } +} + +- (IBAction)cancel:(id)sender { + [self dismissViewControllerAnimated:YES completion:nil]; +} +@end diff --git a/CheckMateShopper/Default-568h@2x.png b/CheckMateShopper/Default-568h@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0891b7aabfcf3422423b109c8beed2bab838c607 GIT binary patch literal 18594 zcmeI4X;f257Jx&9fS`ixvS;&$x8J@slQFSel)6zJN=?13FB7H(lQjRkSy8x_-S~tvu2gzn1oS+dLcF#eqtq$ z%tf9TTvX?`)R@}3uBI;jzS-=ZR-Td&MHaS&;!0?Ni*#$#`n*~CcQK)Q9vAQ~TUpnI!j)a2biYK^R)M~A5wUDZhx?ULMX z3x1P&qt=trOY6P2U67L=m=U?F|5#Uj(eCueNTZaHs_ceWiHeET+j+tp3Jt9g(ekqP z2WOvfR{qV+9r+o4J5?qK>7;;^+I7tGv-i)es$X_D=EoKF+S?zsyj^oRFElP}c}JT< zd8SUs-?O?}2YD#ngKbnHgzHBcboxK_2r9l(?eNCl-pEzkJm}fY?WC*jnS?VBE4EpY zO$fEejz6fU;W2Kl>JeQBZBl-%Irg`obSlg*@4QB;Dd1H7^Oi5wvt4d{RZ!8Og?^aE z)k0$1g+V3fd(gdQ3d&q2q-FL*uy#}|bc^=VhFsl0jBgUGJ+-s3U8MK9A!YJJMxpci z5hJ%|{DwV48fZn0{n5l$N_KcSb#NKE4plB`9I6Zt=Z!~-zw0{9tg$L&Ju1F0X)Cy8 zKF;(&lJ>x)Jw(=;p~sF(Sd9VWGwFE2rnyS9!f^DZ8+aCLq zQ};>lcJ1GDLqjm6Hd>|Eabno@P`~Bn(~6^aD_#yoEH(a?Nm1S<;S+hSxI5d16^<1lEM3NPFi zkqPrpL)+ zgnseFikg`gJVBha1&7C4;O6>h=dt~`ND+;Zd?W(4v2JIb7Pt>Td42%M-Ju-XAH#Pns762L}K3 zDhvsRqN0Ni(1UrishD2YvV?4*h2iFj$+&N||Fn$4n|^NSU+o?~jq`0jVQt8T9l{7b zXiwwODFh2V!Q6sqP9S>WH$oOf$N~=d0-bqTlD61!=`&0eAP-F>XN?*|gtOXX{ zQVTWyYo4ZK0GAw!GHf|pz9`D;-bbb*5LBX*{bnz|+)$@&P9|ORM2o?95{;ejvo&r- zq8cBhTN6nn)7~W>54U)%-F_-b?YKdfk5I8MHcuzBD5)!;yv#Z&R&^y=@=>VTIMy#r zX&U<=BsPkdqcMe<_}2+>H%XKyrr5ZR8_KVe>ZqYN z^=^~TFD};;rHJ$U;{~w^hYojl4hRI@SH$^K{YEo=sg)WY87r!*7blQK&qnpDo0`Vn zkl)9u9g=mCh&ZCJS(L4yN3k0kQ zuvg$h2KEEk51T+O0JQ+r0`R>g{jvqM0Mr6d3qUOZwE!?PI7HY@CE|dr sfw?Q;rAv?G4&^^8-z_>&sWXMxvD*gPOU4CBe-*@OtE+wfmVJNyHv)PfH~;_u literal 0 HcmV?d00001 diff --git a/CheckMateShopper/Default.png b/CheckMateShopper/Default.png new file mode 100644 index 0000000000000000000000000000000000000000..4c8ca6f693f96d511e9113c0eb59eec552354e42 GIT binary patch literal 6540 zcmeAS@N?(olHy`uVBq!ia0y~yU~~ZD2OMlbkt;o0To@QwR5G2N13aCb6#|O#(=u~X z85k@CTSM>X-wqM6>&y>YB4)1;;ojbLbbV-W^iFB1wa3^zCog^LCAReC4K0-?R_2{6 zrP*)4+_uWUy3w5N52M3PW_}MFMP9a~>YLvVZ1D_k*IMQ2QT^fwzoOb(*3gH$%aYWC zkHmcab=va2<#X%jakpJ;<1@F;k__#bwtC&%^D0v(FBh9K&$sK+<}2RJS609D)17$w ztdQP8(eLM8Ka}m_IQ@3wyMKP)l=oM4-?`YS_*P?4V_ORLPxsj&7Ju#kH;>6^Kp?T7~ zl+q?{UOOqV==?+d{=)5s|M~T1mwtH@+Z^$G&eEO9JNP^AX@3jZ*J*!!>lc|1-W%fA z@AOQpXZ_Lt>rxFXrGp*zLPiW@uo_c7C{As>j zWeX)wi+LTp_)@KYZCX{j;H?|1yXT4DnlS(Fr8gyP5|uaX_gLvaW0ScZdnG7o+u{T6 zFI-%d{ls*WuCDa5UJ@|RXv&ejZe}*BMkiWY51&pnRPw(hlykSzvj6e%mYz-GdvzBD zF10?szF_~!jS=?2HyQuPCvARXAe}C}WP|yQ*>5~~=*Nxq8+HHW1~FMDRCP^TcacKuk$ z(U#REVv)D!PhJ*ecH-ELFUrfyV&*)Z)>UCOuS?yd^L@Afk>ihynYPc{^CRwu+JHX+#$@YsC4c|l0tGigsn@jy) zXD($Ouk>H+V(Mr6NQT0S9BFM~V6nkj;1OBOz`zY;a|<&v%$g$sEJPk;hD4M^`1)8S z=jZArrsOB3>Q&?x097+E*i={nnYpPYi3%0DIeEoa6}C!X6;?ntNLXJ<0j#7X+g2&U zH$cHTzbI9~RL@Y)NXd>%K|#T$C?(A*$i)q+9mum)$|xx*u+rBrFE7_CH`dE9O4m2E zw6xSWFw!?N(gmu}Ew0QfNvzP#D^`XW0yD=YwK%ybv!En1KTiQ3|)OBHVcpi zp&D%TL4k-AsNfg_g$9~9p}$+4Ynr|VULLgiakg&)DD)EWO!OHC@snXr}UI${nVUP zpr1>Mf#G6^ng~;pt%^&NvQm>vU@-wn)!_JWN=(;B61LIDR86%A1?G9U(@`={MPdPF zbOKdd`R1o&rd7HmmZaJl85kPr8kp-EnTHsfS{ayIfdU*&4N@e5WSomq6HD@oLh|!- z?7;Dr3*ssm=^5w&a}>G?yzvAH17L|`#|6|0E4}QvA~xC{V_*wu2^AHZU}H9f($4F$btFf{}TLQXUhF5fht1@YV$^ z9BUdFV+73^nIsvRXRM40U}6b7z_6}kHbY}i1LK(xT@6Mi?F5GKBfbp|ZU-3BR*6kv zXcRSQ(0-)mprD+wTr)o_4I;(%zOu)+jEgNB)_SXCVoSa}|F?cfwR!69+L=W3IX z!UiU`0@ph%94Rb33Cpq^IY*r_8XBW%V>G9XmK&p`=xCiXTEmXEH%41uqixaAmicH0 zVYIt6!aI*K%s=kP-v##6IXGZ2Cama>{@)81;C?K-P&M2k<0!GL}5+H~XTq*@SQi|Ft z2*0X`$`8S!qO#)xBeJRkf?;t189=ZB6Imw-h=`q;FP(2UpWZvmJ@=k-@45M(dtb7r zyVEiaLk$=Vw#>zu;st}j6Jf9=m1+nXCFe!$1PrEZ%5Ze_ba8YX_9-*rJujiLuQmJo&2v+Cxes}ec zU|qeux&7*yz#W=X_|wGQskL7*OHNjwFs@sEC+64Hb$Z(#H21Gh$Pe2WzOubdr6fzg z{l{!k%OD?N5Z7j33SoK?YdV6Scm>})U+MIQLNRgIvkZQEc^mP9XBPg%y|S$~Br|;N zk?-!-(Qqh_mQ|6WINQ{hHAjBRV#O#!FkAJ+oxy`L#f8V45*VvWMJFBB5m zG6vOLtDvgoDjHlSq-*h5xM56O>Jjau2f2IxKItIb@coX4XTyf$^{LZG&lI|D95wN1 z!fo0)q>WV7-V;q|A?HR!*bgozJw%j98-~gwBKVV0;=hZIF>7oJSr2YjOWO*rSxz#& z;KXnDrJVZp;Yduiy1-H%s$ZFz6Q=x@$V_B@Tqwl?>6e;EHt|MiK<(#hXQMuj@Jseeh&eN{FxsQ$iw>D1aX1HMMlUbh?Z zmhY4eHffn5&LUbL_}o8|$JYz&$WFiLWmEg0ZPX+;W>@CxQz-%{E5+P7dH9&ey_y$R z@Zzje>2B%z!i!7Brqi{t5Y)~5>vpqRs~2aXD8DVE8vKl=`k(`duI1-k@?!pJ^HA6S zS;3WpuhjQHyoC>X>Xf8gze%_8^#+^RTV>V9&YPAWMjd~%xpSg?ON?kK^X*Pb(o8jR zz;DmaOWMMr6=M~K?MFx4_xDkARTxLJ@W@ohAx z5RD0jGgk?QL@H`VubD2k4}?VtB8@g`%hHBA$2pJ(gK5g1HMNysXEF_BNu-p!&+Qa8_APgopHWnRgg=TZZF*sXWTMQPD z!Q(Au5|+F;7M~`tWbsU98~NA{h0Y7%GB|t&n}w9OOABU4^X*V5xuN;rY(M#ouuqm) zyt!e?28fY!FgP?8GvBsMl_aM^UUVKiGFsleFN?t^<46kO#pF-cX0;sIOb(aM z)^jQgX^Z6pKA9mC@N)_aiHj9HxD2|?A@Y9B_h}(*v3%ek8CXc1Qy^jFPF&zrMa1OZ zSVaF{&ZY|(|H0XE&X>-XQz1`=fF2n@VKC_|h3jlKVM&-jmyMavllcYr`6LVtfq2ou zd+8zkkCB+2)rxq0Lkq_&Ad@g(O8;pAm96>tu79?81T@Z<;gm^3ZtPG-SR94Mr<3tm z9NrR3u*4I5aMlo(09g@8m_;%Rf+XiSa_KZao9n}7N0JrsV#;5Ucr+F*TTzQ8{%f3O zeIUy?WDS|-$LvMc@Z7320)tr}bfIka5hx9H;8H|%our=C+Do0CSFRWue14o5#r8v2 zw=|&r4*eMX%lgCV(ka?*j%H^UuP4LmBC(ON`)&7>NF-|PDRU{-7o`CU0HNbd&c~))@yl9IKu_ zXA+A-!khpP_yx=f#qt2_0ptmgBf4gF!{Y)MW6R$cC1d7@$Yb?+_j zYwfE^5_e`vhT zX=u3r>4$fsxP&apbm@Rcbyuc2T=giqZiMo9@9=oua6#YH0hO-1ak9^rJTPMM qY4Yr5Cu^v99p{E9VdroUHKlRW;M8#BJ^AOQE?e9wSHJo8(7yq;BYKSh literal 0 HcmV?d00001 diff --git a/CheckMateShopper/Models/CMCategory.h b/CheckMateShopper/Models/CMCategory.h new file mode 100644 index 0000000..e81e719 --- /dev/null +++ b/CheckMateShopper/Models/CMCategory.h @@ -0,0 +1,35 @@ +// +// CMCategory.h +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import +#import + +@class CMItem; + +@interface CMCategory : NSManagedObject + +@property (nonatomic, retain) NSString * name; +@property (nonatomic, retain) NSOrderedSet *items; +@end + +@interface CMCategory (CoreDataGeneratedAccessors) + ++ (CMCategory *)findOrBuildByName:(NSString *)name inContext:(NSManagedObjectContext *)context; +- (id)initWithContext:(NSManagedObjectContext *)context; + +- (void)insertObject:(CMItem *)value inItemsAtIndex:(NSUInteger)idx; +- (void)removeObjectFromItemsAtIndex:(NSUInteger)idx; +- (void)insertItems:(NSArray *)value atIndexes:(NSIndexSet *)indexes; +- (void)removeItemsAtIndexes:(NSIndexSet *)indexes; +- (void)replaceObjectInItemsAtIndex:(NSUInteger)idx withObject:(CMItem *)value; +- (void)replaceItemsAtIndexes:(NSIndexSet *)indexes withItems:(NSArray *)values; +- (void)addItemsObject:(CMItem *)value; +- (void)removeItemsObject:(CMItem *)value; +- (void)addItems:(NSOrderedSet *)values; +- (void)removeItems:(NSOrderedSet *)values; +@end diff --git a/CheckMateShopper/Models/CMCategory.m b/CheckMateShopper/Models/CMCategory.m new file mode 100644 index 0000000..0912ba8 --- /dev/null +++ b/CheckMateShopper/Models/CMCategory.m @@ -0,0 +1,62 @@ +// +// CMCategory.m +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import "CMCategory.h" +#import "CMItem.h" + + +@implementation CMCategory + +@dynamic name; +@dynamic items; + ++ (CMCategory *)findOrBuildByName:(NSString *)name inContext:(NSManagedObjectContext *)context +{ + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"CMCategory"]; + fetchRequest.fetchLimit = 1; + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"name = %@", name]; + + NSArray *results = [context executeFetchRequest:fetchRequest error:nil]; + + if (results.count > 0) { + return [results objectAtIndex:0]; + } else { + CMCategory *category = [[CMCategory alloc] initWithContext:context]; + category.name = name; + return category; + } +} + +- (id)initWithContext:(NSManagedObjectContext *)context +{ + NSEntityDescription *entity = [NSEntityDescription entityForName:@"CMCategory" inManagedObjectContext:context]; + self = [super initWithEntity:entity insertIntoManagedObjectContext:context]; + return self; +} + +#pragma mark - NSFetchedResultsSectionInfo properties + +// name is already a property +//- (NSString *)name {} + +- (NSString *)indexTitle +{ + return self.name; +} + +- (NSUInteger)numberOfObjects +{ + return self.items.count; +} + +- (NSArray *)objects +{ + return self.items.array; +} + +@end diff --git a/CheckMateShopper/Models/CMItem.h b/CheckMateShopper/Models/CMItem.h new file mode 100644 index 0000000..f85a601 --- /dev/null +++ b/CheckMateShopper/Models/CMItem.h @@ -0,0 +1,23 @@ +// +// CMItem.h +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import +#import + + +@interface CMItem : NSManagedObject + +@property (nonatomic, retain) NSString * itemId; +@property (nonatomic, retain) NSString * name; +@property (nonatomic, retain) NSManagedObject *category; + ++ (CMItem *)findOrBuildById:(NSString *)itemId inContext:(NSManagedObjectContext *)context; +- (id)initWithContext:(NSManagedObjectContext *)context; +- (void)unpackDictionary:(NSDictionary *)dictionary inContext:(NSManagedObjectContext *)context; + +@end diff --git a/CheckMateShopper/Models/CMItem.m b/CheckMateShopper/Models/CMItem.m new file mode 100644 index 0000000..ee41648 --- /dev/null +++ b/CheckMateShopper/Models/CMItem.m @@ -0,0 +1,53 @@ +// +// CMItem.m +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import "CMItem.h" + + +@implementation CMItem + +@dynamic itemId; +@dynamic name; +@dynamic category; + ++ (CMItem *)findOrBuildById:(NSString *)itemId inContext:(NSManagedObjectContext *)context; +{ + NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"CMItem"]; + fetchRequest.fetchLimit = 1; + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"itemId = %@", itemId]; + + NSArray *results = [context executeFetchRequest:fetchRequest error:nil]; + + if (results.count > 0) { + return [results objectAtIndex:0]; + } else { + return [[CMItem alloc] initWithContext:context]; + } +} + +- (id)initWithContext:(NSManagedObjectContext *)context +{ + NSEntityDescription *entity = [NSEntityDescription entityForName:@"CMItem" inManagedObjectContext:context]; + self = [super initWithEntity:entity insertIntoManagedObjectContext:context]; + return self; +} + +- (void)unpackDictionary:(NSDictionary *)dictionary inContext:(NSManagedObjectContext *)context +{ + NSString *itemId = [[dictionary objectForKey:@"id"] stringValue]; + NSString *itemName = [dictionary objectForKey:@"name"]; + NSString *categoryName = [dictionary objectForKey:@"category"]; + + CMCategory *category = [CMCategory findOrBuildByName:categoryName inContext:context]; + + self.itemId = itemId; + self.name = itemName; + self.category = category; +} + +@end diff --git a/CheckMateShopper/Storyboard.storyboard b/CheckMateShopper/Storyboard.storyboard new file mode 100644 index 0000000..048c3cc --- /dev/null +++ b/CheckMateShopper/Storyboard.storyboard @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CheckMateShopper/Vendor/CMShopperHTTPClient/CMShopperHTTPClient.h b/CheckMateShopper/Vendor/CMShopperHTTPClient/CMShopperHTTPClient.h new file mode 100644 index 0000000..81b0ea0 --- /dev/null +++ b/CheckMateShopper/Vendor/CMShopperHTTPClient/CMShopperHTTPClient.h @@ -0,0 +1,20 @@ +// +// CMShopperHTTPClient.h +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import + +@interface CMShopperHTTPClient : NSObject ++ (CMShopperHTTPClient *)sharedInstance; +- (void)listItemsOnComplete:(void(^)(NSArray *items, NSError *error))completeBlock; +- (void)createItemWithName:(NSString *)name category:(NSString *)category onComplete:(void(^)(NSDictionary *item, NSError *error))completeBlock; +- (void)updateItemWithId:(NSString *)itemId name:(NSString *)name category:(NSString *)category onComplete:(void(^)(NSDictionary *item, NSError *error))completeBlock; +- (void)deleteItemWithId:(NSString *)itemId onComplete:(void(^)(NSError *error))completeBlock; + +//- (void)createItem:(CMItem *)item onComplete:(void(^)(CMItem *item, NSError *error))completeBlock; +//- (void)updateItem:(CMItem *)item onComplete:(void(^)(CMItem *item, NSError *error))completeBlock; +@end diff --git a/CheckMateShopper/Vendor/CMShopperHTTPClient/CMShopperHTTPClient.m b/CheckMateShopper/Vendor/CMShopperHTTPClient/CMShopperHTTPClient.m new file mode 100644 index 0000000..d6c3088 --- /dev/null +++ b/CheckMateShopper/Vendor/CMShopperHTTPClient/CMShopperHTTPClient.m @@ -0,0 +1,124 @@ +// +// CMShopperHTTPClient.m +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import "CMShopperHTTPClient.h" + +@interface CMShopperHTTPClient() +@property (nonatomic, strong) NSURL *baseUrl; +@property (nonatomic, strong) NSString *token; +@end + +@implementation CMShopperHTTPClient + ++ (CMShopperHTTPClient *)sharedInstance +{ + static CMShopperHTTPClient *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[self alloc] init]; + }); + return sharedInstance; +} + +- (id)init +{ + self = [super init]; + if (self) { + self.baseUrl = [NSURL URLWithString:@"http://cmshopper.herokuapp.com"]; + self.token = @"56ef17da1442a79a1011388cdb390857"; + } + + return self; +} + +- (void)listItemsOnComplete:(void(^)(NSArray *items, NSError *error))completeBlock +{ + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.baseUrl URLByAppendingPathComponent:@"items.json"]]; + request.HTTPMethod = @"GET"; + [request setValue:self.token forHTTPHeaderField:@"X-CM-Authorization"]; + [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; + + [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { + if (error) { + completeBlock(nil, error); + } else { + NSArray *items = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; + completeBlock(items, nil); + } + }]; +} + +- (void)createItemWithName:(NSString *)name category:(NSString *)category onComplete:(void(^)(NSDictionary *item, NSError *error))completeBlock +{ + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.baseUrl URLByAppendingPathComponent:@"items.json"]]; + request.HTTPMethod = @"POST"; + [request setValue:self.token forHTTPHeaderField:@"X-CM-Authorization"]; + [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; + + NSDictionary *itemJsonData = [NSDictionary dictionaryWithObjectsAndKeys:name, @"name", category, @"category", nil]; + NSDictionary *topLevelItemData = [NSDictionary dictionaryWithObject:itemJsonData forKey:@"item"]; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:topLevelItemData options:0 error:nil]; + + request.HTTPBody = jsonData; + + [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { + if (error) { + completeBlock(nil, error); + } else { + NSDictionary *item = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; + completeBlock(item, nil); + } + }]; +} + +- (void)updateItemWithId:(NSString *)itemId name:(NSString *)name category:(NSString *)category onComplete:(void(^)(NSDictionary *item, NSError *error))completeBlock +{ + NSString *path = [NSString stringWithFormat:@"items/%@.json", itemId]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.baseUrl URLByAppendingPathComponent:path]]; + request.HTTPMethod = @"PUT"; + [request setValue:self.token forHTTPHeaderField:@"X-CM-Authorization"]; + [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; + + NSDictionary *itemJsonData = [NSDictionary dictionaryWithObjectsAndKeys:name, @"name", category, @"category", nil]; + NSDictionary *topLevelItemData = [NSDictionary dictionaryWithObject:itemJsonData forKey:@"item"]; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:topLevelItemData options:0 error:nil]; + + request.HTTPBody = jsonData; + + [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { + if (error) { + completeBlock(nil, error); + } else { + NSDictionary *item = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; + completeBlock(item, nil); + } + }]; +} + +- (void)deleteItemWithId:(NSString *)itemId onComplete:(void(^)(NSError *error))completeBlock; +{ + NSString *path = [NSString stringWithFormat:@"items/%@.json", itemId]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.baseUrl URLByAppendingPathComponent:path]]; + request.HTTPMethod = @"DELETE"; + [request setValue:self.token forHTTPHeaderField:@"X-CM-Authorization"]; + [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; + + [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { + if (error) { + completeBlock(error); + } else { + completeBlock(nil); + } + }]; +} + +@end diff --git a/CheckMateShopper/en.lproj/InfoPlist.strings b/CheckMateShopper/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/CheckMateShopper/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/CheckMateShopper/main.m b/CheckMateShopper/main.m new file mode 100644 index 0000000..fb89d5f --- /dev/null +++ b/CheckMateShopper/main.m @@ -0,0 +1,18 @@ +// +// main.m +// CheckMateShopper +// +// Created by Michael Enriquez on 2/13/13. +// Copyright (c) 2013 Mike Enriquez. All rights reserved. +// + +#import + +#import "CMAppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([CMAppDelegate class])); + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..cf023d8 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# CheckMate Shopper + +Sample iOS Code! + +## TODO + +* Refactor CMShopperHTTPClient. Building the request and sending it can be abstracted between the three methods. +* Refactor new item and edit item views into a single view. The view will contain the name text field, category text field, and save button. This would also simplify validations. +* Display an error to user on network failures. +* Handle deletes made from other clients. This can be done by deleting all of the existing items before loading them from the server. +* Fix animation when adding/editing. +* Create protocol for dismissing new/edit item view controllers. They shouldn't be dismissing themselves, the parent should do that.