From b0a637520efca6655a785c544953c142450f0b5a Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Fri, 5 Jun 2015 02:21:34 +0900 Subject: [PATCH] updated demo app --- CoreStore.xcodeproj/project.pbxproj | 13 ++ CoreStore/Logging/DefaultLogger.swift | 2 + .../CoreStoreDemo.xcodeproj/project.pbxproj | 22 ++- CoreStoreDemo/CoreStoreDemo/AppDelegate.swift | 1 + .../CoreStoreDemo/Base.lproj/LaunchScreen.xib | 14 +- .../CoreStoreDemo/Base.lproj/Main.storyboard | 175 ++++++++++++------ CoreStoreDemo/CoreStoreDemo/Info.plist | 6 +- .../CustomLoggerViewController.swift | 108 +++++++++++ 8 files changed, 279 insertions(+), 62 deletions(-) create mode 100644 CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index a92b96d..c99c32d 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -80,6 +80,13 @@ remoteGlobalIDString = 2FBBCAD619A9FE610070E4AB; remoteInfo = GCDKitTests; }; + B5D9C9081B20A87D00E64F0E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = B5D806C51A34715700A44484 /* GCDKit.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 2FBBCACA19A9FE610070E4AB; + remoteInfo = GCDKit; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -396,6 +403,7 @@ buildRules = ( ); dependencies = ( + B5D9C9091B20A87D00E64F0E /* PBXTargetDependency */, ); name = CoreStore; productName = CoreStore; @@ -563,6 +571,11 @@ target = 2F03A52F19C5C6DA005002A5 /* CoreStore */; targetProxy = B5D372871A39CF4D00F583D9 /* PBXContainerItemProxy */; }; + B5D9C9091B20A87D00E64F0E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = GCDKit; + targetProxy = B5D9C9081B20A87D00E64F0E /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ diff --git a/CoreStore/Logging/DefaultLogger.swift b/CoreStore/Logging/DefaultLogger.swift index 7961dd5..ca2907f 100644 --- a/CoreStore/Logging/DefaultLogger.swift +++ b/CoreStore/Logging/DefaultLogger.swift @@ -36,6 +36,8 @@ The `DefaultLogger` is a basic implementation of the `CoreStoreLogger` protocol. - The `assert(...)` method calls `assert(...)` on the arguments. */ public final class DefaultLogger: CoreStoreLogger { + + public init() { } public func log(#level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { diff --git a/CoreStoreDemo/CoreStoreDemo.xcodeproj/project.pbxproj b/CoreStoreDemo/CoreStoreDemo.xcodeproj/project.pbxproj index 65a27f2..4139148 100644 --- a/CoreStoreDemo/CoreStoreDemo.xcodeproj/project.pbxproj +++ b/CoreStoreDemo/CoreStoreDemo.xcodeproj/project.pbxproj @@ -23,8 +23,11 @@ B54AAD5E1AF4D26E00848AE0 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = B54AAD5C1AF4D26E00848AE0 /* LaunchScreen.xib */; }; B566E32A1B117B1F00F4F0C6 /* StackSetupDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B566E3291B117B1F00F4F0C6 /* StackSetupDemoViewController.swift */; }; B566E3321B11DF3200F4F0C6 /* UserAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = B566E3311B11DF3200F4F0C6 /* UserAccount.swift */; }; + B56964C91B20AC780075EE4A /* CustomLoggerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56964C81B20AC780075EE4A /* CustomLoggerViewController.swift */; }; B583A9201AF5F542001F76AF /* CoreStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B583A91B1AF5F4F4001F76AF /* CoreStore.framework */; }; B583A9211AF5F542001F76AF /* CoreStore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B583A91B1AF5F4F4001F76AF /* CoreStore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + B5D9C9191B20AB1900E64F0E /* GCDKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D9C9181B20AB1900E64F0E /* GCDKit.framework */; }; + B5D9C91A1B20AB1900E64F0E /* GCDKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B5D9C9181B20AB1900E64F0E /* GCDKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B5E7240F1B11F993006FB83F /* TwitterAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E7240E1B11F993006FB83F /* TwitterAccount.swift */; }; B5E724111B11F994006FB83F /* FacebookAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E724101B11F994006FB83F /* FacebookAccount.swift */; }; /* End PBXBuildFile section */ @@ -67,6 +70,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( + B5D9C91A1B20AB1900E64F0E /* GCDKit.framework in Embed Frameworks */, B583A9211AF5F542001F76AF /* CoreStore.framework in Embed Frameworks */, ); name = "Embed Frameworks"; @@ -93,8 +97,9 @@ B54AAD5D1AF4D26E00848AE0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; B566E3291B117B1F00F4F0C6 /* StackSetupDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StackSetupDemoViewController.swift; sourceTree = ""; }; B566E3311B11DF3200F4F0C6 /* UserAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserAccount.swift; sourceTree = ""; }; + B56964C81B20AC780075EE4A /* CustomLoggerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomLoggerViewController.swift; sourceTree = ""; }; B583A9141AF5F4F3001F76AF /* CoreStore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = CoreStore.xcodeproj; path = ../CoreStore.xcodeproj; sourceTree = ""; }; - B583A9251AF5F547001F76AF /* GCDKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = GCDKit.framework; path = "/Users/johnestropia/Library/Developer/Xcode/DerivedData/CoreStoreDemo-ftknhsqfpsthfogvisxisgpbbhsj/Build/Products/Debug-iphoneos/GCDKit.framework"; sourceTree = ""; }; + B5D9C9181B20AB1900E64F0E /* GCDKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = GCDKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B5E7240E1B11F993006FB83F /* TwitterAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwitterAccount.swift; sourceTree = ""; }; B5E724101B11F994006FB83F /* FacebookAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FacebookAccount.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -106,6 +111,7 @@ files = ( B52977E11B120F8A003D50A5 /* CoreLocation.framework in Frameworks */, B52977DF1B120F83003D50A5 /* MapKit.framework in Frameworks */, + B5D9C9191B20AB1900E64F0E /* GCDKit.framework in Frameworks */, B583A9201AF5F542001F76AF /* CoreStore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -138,9 +144,9 @@ isa = PBXGroup; children = ( B583A9141AF5F4F3001F76AF /* CoreStore.xcodeproj */, + B5D9C9181B20AB1900E64F0E /* GCDKit.framework */, B52977E01B120F8A003D50A5 /* CoreLocation.framework */, B52977DE1B120F83003D50A5 /* MapKit.framework */, - B583A9251AF5F547001F76AF /* GCDKit.framework */, ); name = Frameworks; sourceTree = ""; @@ -169,6 +175,7 @@ B566E3271B117AE700F4F0C6 /* Stack Setup Demo */, B503FADA1AFDC71700F90881 /* List and Object Observers Demo */, B52977DB1B120F2C003D50A5 /* Transactions Demo */, + B56964C61B20AC200075EE4A /* Loggers Demo */, B54AAD571AF4D26E00848AE0 /* Main.storyboard */, B54AAD5A1AF4D26E00848AE0 /* Images.xcassets */, B54AAD5C1AF4D26E00848AE0 /* LaunchScreen.xib */, @@ -197,6 +204,14 @@ path = "Stack Setup Demo"; sourceTree = ""; }; + B56964C61B20AC200075EE4A /* Loggers Demo */ = { + isa = PBXGroup; + children = ( + B56964C81B20AC780075EE4A /* CustomLoggerViewController.swift */, + ); + path = "Loggers Demo"; + sourceTree = ""; + }; B583A9151AF5F4F3001F76AF /* Products */ = { isa = PBXGroup; children = ( @@ -306,6 +321,7 @@ B52977E41B121635003D50A5 /* Place.swift in Sources */, B503FAE01AFDC71700F90881 /* ObjectObserverDemoViewController.swift in Sources */, B52977D91B120B80003D50A5 /* ObserversViewController.swift in Sources */, + B56964C91B20AC780075EE4A /* CustomLoggerViewController.swift in Sources */, B566E32A1B117B1F00F4F0C6 /* StackSetupDemoViewController.swift in Sources */, B5E724111B11F994006FB83F /* FacebookAccount.swift in Sources */, B5E7240F1B11F993006FB83F /* TwitterAccount.swift in Sources */, @@ -441,6 +457,7 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/CoreStoreDemo-ftknhsqfpsthfogvisxisgpbbhsj/Build/Products/Debug-iphoneos", + "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/CoreStoreDemo-bnajhooxbfnxepepdtkvkfplrqyq/Build/Products/Debug-iphoneos", ); INFOPLIST_FILE = CoreStoreDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -456,6 +473,7 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/CoreStoreDemo-ftknhsqfpsthfogvisxisgpbbhsj/Build/Products/Debug-iphoneos", + "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/CoreStoreDemo-bnajhooxbfnxepepdtkvkfplrqyq/Build/Products/Debug-iphoneos", ); INFOPLIST_FILE = CoreStoreDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; diff --git a/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift b/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift index 0630c24..c65b6d9 100644 --- a/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift +++ b/CoreStoreDemo/CoreStoreDemo/AppDelegate.swift @@ -20,6 +20,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + application.statusBarStyle = .LightContent return true } } diff --git a/CoreStoreDemo/CoreStoreDemo/Base.lproj/LaunchScreen.xib b/CoreStoreDemo/CoreStoreDemo/Base.lproj/LaunchScreen.xib index 08ae6ad..c3e905c 100644 --- a/CoreStoreDemo/CoreStoreDemo/Base.lproj/LaunchScreen.xib +++ b/CoreStoreDemo/CoreStoreDemo/Base.lproj/LaunchScreen.xib @@ -1,7 +1,7 @@ - + - + @@ -14,17 +14,17 @@ - @@ -288,7 +292,7 @@ @@ -399,6 +403,12 @@ + + + + + + @@ -430,9 +440,9 @@ @@ -488,9 +498,9 @@ @@ -533,10 +543,11 @@ - - + + - + + @@ -560,8 +571,8 @@ - - + + @@ -585,6 +596,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -594,10 +664,11 @@ - - + + - + + diff --git a/CoreStoreDemo/CoreStoreDemo/Info.plist b/CoreStoreDemo/CoreStoreDemo/Info.plist index 880f2cf..80a2279 100644 --- a/CoreStoreDemo/CoreStoreDemo/Info.plist +++ b/CoreStoreDemo/CoreStoreDemo/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.johnestropia.HardcoreDataDemo + com.johnestropia.CoreStoreDemo CFBundleInfoDictionaryVersion 6.0 CFBundleName @@ -30,6 +30,8 @@ armv7 + UIStatusBarStyle + UIStatusBarStyleLightContent UIStatusBarTintParameters UINavigationBar @@ -44,5 +46,7 @@ UIInterfaceOrientationPortrait + UIViewControllerBasedStatusBarAppearance + diff --git a/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift b/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift new file mode 100644 index 0000000..068ee9b --- /dev/null +++ b/CoreStoreDemo/CoreStoreDemo/Loggers Demo/CustomLoggerViewController.swift @@ -0,0 +1,108 @@ +// +// CustomLoggerViewController.swift +// CoreStoreDemo +// +// Created by John Rommel Estropia on 2015/06/05. +// Copyright (c) 2015 John Rommel Estropia. All rights reserved. +// + +import UIKit +import CoreStore +import GCDKit + + +// MARK: - CustomLoggerViewController + +class CustomLoggerViewController: UIViewController, CoreStoreLogger { + + // MARK: NSObject + + deinit { + + CoreStore.logger = DefaultLogger() + } + + + // MARK: UIViewController + + override func viewDidLoad() { + + super.viewDidLoad() + + CoreStore.logger = self + } + + override func viewDidAppear(animated: Bool) { + + super.viewDidAppear(animated) + + let alert = UIAlertController( + title: "Logger Demo", + message: "This demo shows how to plug-in any logging framework to CoreStore.\n\nThe view controller implements CoreStoreLogger and appends all logs to the text view.", + preferredStyle: .Alert + ) + alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil)) + self.presentViewController(alert, animated: true, completion: nil) + } + + + // MARK: CoreStoreLogger + + func log(#level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { + + GCDQueue.Main.async { [weak self] in + + self?.textView?.insertText("\(fileName.stringValue.lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Log] \(message)\n\n") + } + } + + func handleError(#error: NSError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { + + GCDQueue.Main.async { [weak self] in + + self?.textView?.insertText("\(fileName.stringValue.lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Error] \(message): \(error)\n\n") + } + } + + func assert(@autoclosure condition: () -> Bool, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) { + + if condition() { + + return + } + + GCDQueue.Main.async { [weak self] in + + self?.textView?.insertText("\(fileName.stringValue.lastPathComponent):\(lineNumber) \(functionName)\n ↪︎ [Assert] \(message)\n\n") + } + } + + + // MARK: Private + + @IBOutlet dynamic weak var textView: UITextView? + @IBOutlet dynamic weak var segmentedControl: UISegmentedControl? + + @IBAction dynamic func segmentedControlValueChanged(sender: AnyObject?) { + + switch self.segmentedControl?.selectedSegmentIndex { + + case .Some(0): + CoreStore.beginAsynchronous { (transaction) -> Void in + transaction.create(Into(UserAccount)) + } + + case .Some(1): + CoreStore.addSQLiteStore("dummy.sqlite", configuration: "test1") + CoreStore.addSQLiteStore("dummy.sqlite", configuration: "test2") + + case .Some(2): + CoreStore.beginAsynchronous { (transaction) -> Void in + transaction.commit() + transaction.commit() + } + + default: return + } + } +}