From d06ad0f7f76bd9fad4bb15ffdcdb7915d92e0e53 Mon Sep 17 00:00:00 2001 From: Hin Wong Date: Fri, 10 Apr 2020 09:49:38 -0600 Subject: [PATCH 1/6] model complete --- .../PairGenrator.xcodeproj/project.pbxproj | 388 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../PairGenrator/Model/CoreData.swift | 43 ++ .../Model/Person+Convenience.swift | 18 + .../.xccurrentversion | 8 + .../PairGenrator.xcdatamodel/contents | 9 + .../PairGenrator/Resource/AppDelegate.swift | 82 ++++ .../AppIcon.appiconset/Contents.json | 98 +++++ .../Resource/Assets.xcassets/Contents.json | 6 + PairGenrator/PairGenrator/Resource/Info.plist | 64 +++ .../PairGenrator/Resource/SceneDelegate.swift | 56 +++ .../Base.lproj/LaunchScreen.storyboard | 25 ++ .../Storyboard/Base.lproj/Main.storyboard | 24 ++ 14 files changed, 836 insertions(+) create mode 100644 PairGenrator/PairGenrator.xcodeproj/project.pbxproj create mode 100644 PairGenrator/PairGenrator.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 PairGenrator/PairGenrator.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 PairGenrator/PairGenrator/Model/CoreData.swift create mode 100644 PairGenrator/PairGenrator/Model/Person+Convenience.swift create mode 100644 PairGenrator/PairGenrator/PairGenrator.xcdatamodeld/.xccurrentversion create mode 100644 PairGenrator/PairGenrator/PairGenrator.xcdatamodeld/PairGenrator.xcdatamodel/contents create mode 100644 PairGenrator/PairGenrator/Resource/AppDelegate.swift create mode 100644 PairGenrator/PairGenrator/Resource/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 PairGenrator/PairGenrator/Resource/Assets.xcassets/Contents.json create mode 100644 PairGenrator/PairGenrator/Resource/Info.plist create mode 100644 PairGenrator/PairGenrator/Resource/SceneDelegate.swift create mode 100644 PairGenrator/PairGenrator/Storyboard/Base.lproj/LaunchScreen.storyboard create mode 100644 PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard diff --git a/PairGenrator/PairGenrator.xcodeproj/project.pbxproj b/PairGenrator/PairGenrator.xcodeproj/project.pbxproj new file mode 100644 index 0000000..afb5786 --- /dev/null +++ b/PairGenrator/PairGenrator.xcodeproj/project.pbxproj @@ -0,0 +1,388 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 4E941F1F2440CAC700B8F869 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F1E2440CAC700B8F869 /* AppDelegate.swift */; }; + 4E941F212440CAC700B8F869 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F202440CAC700B8F869 /* SceneDelegate.swift */; }; + 4E941F262440CAC700B8F869 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4E941F242440CAC700B8F869 /* Main.storyboard */; }; + 4E941F292440CAC700B8F869 /* PairGenrator.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F272440CAC700B8F869 /* PairGenrator.xcdatamodeld */; }; + 4E941F2B2440CAC800B8F869 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4E941F2A2440CAC800B8F869 /* Assets.xcassets */; }; + 4E941F2E2440CAC800B8F869 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4E941F2C2440CAC800B8F869 /* LaunchScreen.storyboard */; }; + 4E941F382440CB8900B8F869 /* CoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F372440CB8900B8F869 /* CoreData.swift */; }; + 4E941F3A2440CBF300B8F869 /* Person+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F392440CBF300B8F869 /* Person+Convenience.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 4E941F1B2440CAC700B8F869 /* PairGenrator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PairGenrator.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 4E941F1E2440CAC700B8F869 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 4E941F202440CAC700B8F869 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 4E941F252440CAC700B8F869 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 4E941F282440CAC700B8F869 /* PairGenrator.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = PairGenrator.xcdatamodel; sourceTree = ""; }; + 4E941F2A2440CAC800B8F869 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 4E941F2D2440CAC800B8F869 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 4E941F2F2440CAC800B8F869 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4E941F372440CB8900B8F869 /* CoreData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreData.swift; sourceTree = ""; }; + 4E941F392440CBF300B8F869 /* Person+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Person+Convenience.swift"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4E941F182440CAC700B8F869 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4E941F122440CAC700B8F869 = { + isa = PBXGroup; + children = ( + 4E941F1D2440CAC700B8F869 /* PairGenrator */, + 4E941F1C2440CAC700B8F869 /* Products */, + ); + sourceTree = ""; + }; + 4E941F1C2440CAC700B8F869 /* Products */ = { + isa = PBXGroup; + children = ( + 4E941F1B2440CAC700B8F869 /* PairGenrator.app */, + ); + name = Products; + sourceTree = ""; + }; + 4E941F1D2440CAC700B8F869 /* PairGenrator */ = { + isa = PBXGroup; + children = ( + 4E941F352440CAFC00B8F869 /* Resource */, + 4E941F362440CB1F00B8F869 /* Storyboard */, + 4E941F272440CAC700B8F869 /* PairGenrator.xcdatamodeld */, + 4E941F3B2440CC3B00B8F869 /* Model */, + ); + path = PairGenrator; + sourceTree = ""; + }; + 4E941F352440CAFC00B8F869 /* Resource */ = { + isa = PBXGroup; + children = ( + 4E941F1E2440CAC700B8F869 /* AppDelegate.swift */, + 4E941F202440CAC700B8F869 /* SceneDelegate.swift */, + 4E941F2A2440CAC800B8F869 /* Assets.xcassets */, + 4E941F2F2440CAC800B8F869 /* Info.plist */, + ); + path = Resource; + sourceTree = ""; + }; + 4E941F362440CB1F00B8F869 /* Storyboard */ = { + isa = PBXGroup; + children = ( + 4E941F242440CAC700B8F869 /* Main.storyboard */, + 4E941F2C2440CAC800B8F869 /* LaunchScreen.storyboard */, + ); + path = Storyboard; + sourceTree = ""; + }; + 4E941F3B2440CC3B00B8F869 /* Model */ = { + isa = PBXGroup; + children = ( + 4E941F372440CB8900B8F869 /* CoreData.swift */, + 4E941F392440CBF300B8F869 /* Person+Convenience.swift */, + ); + path = Model; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4E941F1A2440CAC700B8F869 /* PairGenrator */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4E941F322440CAC800B8F869 /* Build configuration list for PBXNativeTarget "PairGenrator" */; + buildPhases = ( + 4E941F172440CAC700B8F869 /* Sources */, + 4E941F182440CAC700B8F869 /* Frameworks */, + 4E941F192440CAC700B8F869 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PairGenrator; + productName = PairGenrator; + productReference = 4E941F1B2440CAC700B8F869 /* PairGenrator.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4E941F132440CAC700B8F869 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1140; + LastUpgradeCheck = 1140; + ORGANIZATIONNAME = "Hin Wong"; + TargetAttributes = { + 4E941F1A2440CAC700B8F869 = { + CreatedOnToolsVersion = 11.4; + }; + }; + }; + buildConfigurationList = 4E941F162440CAC700B8F869 /* Build configuration list for PBXProject "PairGenrator" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 4E941F122440CAC700B8F869; + productRefGroup = 4E941F1C2440CAC700B8F869 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4E941F1A2440CAC700B8F869 /* PairGenrator */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4E941F192440CAC700B8F869 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4E941F2E2440CAC800B8F869 /* LaunchScreen.storyboard in Resources */, + 4E941F2B2440CAC800B8F869 /* Assets.xcassets in Resources */, + 4E941F262440CAC700B8F869 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4E941F172440CAC700B8F869 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4E941F382440CB8900B8F869 /* CoreData.swift in Sources */, + 4E941F1F2440CAC700B8F869 /* AppDelegate.swift in Sources */, + 4E941F212440CAC700B8F869 /* SceneDelegate.swift in Sources */, + 4E941F3A2440CBF300B8F869 /* Person+Convenience.swift in Sources */, + 4E941F292440CAC700B8F869 /* PairGenrator.xcdatamodeld in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 4E941F242440CAC700B8F869 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4E941F252440CAC700B8F869 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 4E941F2C2440CAC800B8F869 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4E941F2D2440CAC800B8F869 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 4E941F302440CAC800B8F869 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.4; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 4E941F312440CAC800B8F869 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.4; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4E941F332440CAC800B8F869 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = ZZR7FKBFJP; + INFOPLIST_FILE = PairGenrator/Resource/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.HinWong.PairGenrator; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 4E941F342440CAC800B8F869 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = ZZR7FKBFJP; + INFOPLIST_FILE = PairGenrator/Resource/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.HinWong.PairGenrator; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4E941F162440CAC700B8F869 /* Build configuration list for PBXProject "PairGenrator" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4E941F302440CAC800B8F869 /* Debug */, + 4E941F312440CAC800B8F869 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4E941F322440CAC800B8F869 /* Build configuration list for PBXNativeTarget "PairGenrator" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4E941F332440CAC800B8F869 /* Debug */, + 4E941F342440CAC800B8F869 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + 4E941F272440CAC700B8F869 /* PairGenrator.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + 4E941F282440CAC700B8F869 /* PairGenrator.xcdatamodel */, + ); + currentVersion = 4E941F282440CAC700B8F869 /* PairGenrator.xcdatamodel */; + path = PairGenrator.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ + }; + rootObject = 4E941F132440CAC700B8F869 /* Project object */; +} diff --git a/PairGenrator/PairGenrator.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/PairGenrator/PairGenrator.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1585ed5 --- /dev/null +++ b/PairGenrator/PairGenrator.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/PairGenrator/PairGenrator.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/PairGenrator/PairGenrator.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/PairGenrator/PairGenrator.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/PairGenrator/PairGenrator/Model/CoreData.swift b/PairGenrator/PairGenrator/Model/CoreData.swift new file mode 100644 index 0000000..70ff0e8 --- /dev/null +++ b/PairGenrator/PairGenrator/Model/CoreData.swift @@ -0,0 +1,43 @@ +// +// CoreData.swift +// PairGenrator +// +// Created by Hin Wong on 4/10/20. +// Copyright © 2020 Hin Wong. All rights reserved. +// + +import Foundation +import CoreData + +enum CoreDataStack { + + //MARK: - Core data stack + static let container: NSPersistentContainer = { + let container = NSPersistentContainer(name: "PlaylistCoreData") + container.loadPersistentStores { (_, error) in + if let error = error { + fatalError("Failed to load persistet stores \(error)") + } + } + return container + } () + + static var context: NSManagedObjectContext { + return container.viewContext + } + + //MARK: - Core data saving + + static func saveContext () { + let context = CoreDataStack.context + if context.hasChanges { + do { + try context.save() + } catch { + let nserror = error as NSError + fatalError("Unresolved error saving Core Data context:\n\(nserror), \(nserror.userInfo)") + } + } + } +} + diff --git a/PairGenrator/PairGenrator/Model/Person+Convenience.swift b/PairGenrator/PairGenrator/Model/Person+Convenience.swift new file mode 100644 index 0000000..e058bb4 --- /dev/null +++ b/PairGenrator/PairGenrator/Model/Person+Convenience.swift @@ -0,0 +1,18 @@ +// +// Person+Convenience.swift +// PairGenrator +// +// Created by Hin Wong on 4/10/20. +// Copyright © 2020 Hin Wong. All rights reserved. +// + +import Foundation +import CoreData + +extension Person { + @discardableResult + convenience init(name: String, context: NSManagedObjectContext = CoreDataStack.context) { + self.init(context: context) + self.name = name + } +} diff --git a/PairGenrator/PairGenrator/PairGenrator.xcdatamodeld/.xccurrentversion b/PairGenrator/PairGenrator/PairGenrator.xcdatamodeld/.xccurrentversion new file mode 100644 index 0000000..9c6b459 --- /dev/null +++ b/PairGenrator/PairGenrator/PairGenrator.xcdatamodeld/.xccurrentversion @@ -0,0 +1,8 @@ + + + + + _XCCurrentVersionName + PairGenrator.xcdatamodel + + diff --git a/PairGenrator/PairGenrator/PairGenrator.xcdatamodeld/PairGenrator.xcdatamodel/contents b/PairGenrator/PairGenrator/PairGenrator.xcdatamodeld/PairGenrator.xcdatamodel/contents new file mode 100644 index 0000000..769b265 --- /dev/null +++ b/PairGenrator/PairGenrator/PairGenrator.xcdatamodeld/PairGenrator.xcdatamodel/contents @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/PairGenrator/PairGenrator/Resource/AppDelegate.swift b/PairGenrator/PairGenrator/Resource/AppDelegate.swift new file mode 100644 index 0000000..14c5415 --- /dev/null +++ b/PairGenrator/PairGenrator/Resource/AppDelegate.swift @@ -0,0 +1,82 @@ +// +// AppDelegate.swift +// PairGenrator +// +// Created by Hin Wong on 4/10/20. +// Copyright © 2020 Hin Wong. All rights reserved. +// + +import UIKit +import CoreData + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + // MARK: - Core Data stack + + lazy var persistentContainer: NSPersistentContainer = { + /* + The persistent container for the application. This implementation + creates and returns a container, having loaded the store for the + application to it. This property is optional since there are legitimate + error conditions that could cause the creation of the store to fail. + */ + let container = NSPersistentContainer(name: "PairGenrator") + container.loadPersistentStores(completionHandler: { (storeDescription, error) in + if let error = error as NSError? { + // Replace this implementation with code to handle the error appropriately. + // fatalError() 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 parent directory does not exist, cannot be created, or disallows writing. + * The persistent store is not accessible, due to permissions or data protection when the device is locked. + * The device is out of space. + * The store could not be migrated to the current model version. + Check the error message to determine what the actual problem was. + */ + fatalError("Unresolved error \(error), \(error.userInfo)") + } + }) + return container + }() + + // MARK: - Core Data Saving support + + func saveContext () { + let context = persistentContainer.viewContext + if context.hasChanges { + do { + try context.save() + } catch { + // Replace this implementation with code to handle the error appropriately. + // fatalError() 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. + let nserror = error as NSError + fatalError("Unresolved error \(nserror), \(nserror.userInfo)") + } + } + } + +} + diff --git a/PairGenrator/PairGenrator/Resource/Assets.xcassets/AppIcon.appiconset/Contents.json b/PairGenrator/PairGenrator/Resource/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..9221b9b --- /dev/null +++ b/PairGenrator/PairGenrator/Resource/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PairGenrator/PairGenrator/Resource/Assets.xcassets/Contents.json b/PairGenrator/PairGenrator/Resource/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/PairGenrator/PairGenrator/Resource/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PairGenrator/PairGenrator/Resource/Info.plist b/PairGenrator/PairGenrator/Resource/Info.plist new file mode 100644 index 0000000..2a3483c --- /dev/null +++ b/PairGenrator/PairGenrator/Resource/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/PairGenrator/PairGenrator/Resource/SceneDelegate.swift b/PairGenrator/PairGenrator/Resource/SceneDelegate.swift new file mode 100644 index 0000000..14670d2 --- /dev/null +++ b/PairGenrator/PairGenrator/Resource/SceneDelegate.swift @@ -0,0 +1,56 @@ +// +// SceneDelegate.swift +// PairGenrator +// +// Created by Hin Wong on 4/10/20. +// Copyright © 2020 Hin Wong. All rights reserved. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + + // Save changes in the application's managed object context when the application transitions to the background. + (UIApplication.shared.delegate as? AppDelegate)?.saveContext() + } + + +} + diff --git a/PairGenrator/PairGenrator/Storyboard/Base.lproj/LaunchScreen.storyboard b/PairGenrator/PairGenrator/Storyboard/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/PairGenrator/PairGenrator/Storyboard/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard b/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard new file mode 100644 index 0000000..25a7638 --- /dev/null +++ b/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + From 138b1c4e192d44f800fa80c367fb57fbc29b6f1e Mon Sep 17 00:00:00 2001 From: Hin Wong Date: Fri, 10 Apr 2020 10:10:09 -0600 Subject: [PATCH 2/6] CRUD function complete --- PairGenrator/.DS_Store | Bin 0 -> 6148 bytes .../PairGenrator.xcodeproj/project.pbxproj | 12 +++++ .../ModelController/PersonController.swift | 41 ++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 PairGenrator/.DS_Store create mode 100644 PairGenrator/PairGenrator/ModelController/PersonController.swift diff --git a/PairGenrator/.DS_Store b/PairGenrator/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9e965525095912c83c1dc9ff7995bd240d0c0f2b GIT binary patch literal 6148 zcmeHK%SuBr5Iv(^6x?(rF7pLK{~(k~w?cnFX~hTHdl7{$^Na5N7|%Q^E#8frA~FNX znMWo!IdC%x0GYk7r@#cjm`zbs84z_3hE8IzqSzb@++l-P+~RFuqQB_UwV&gfD}Lm< z_t)RizQh(QbXap=J?#!p&-c^is(a~uGasM7&F>%f@`4jDLgbE5VCioep}BmXcZtz;k>_-72r zXuh1!xT&bEKenf}wy@o>spz<-3Wd6rVxpB|8hVagSkU7|b;fI8bJSVXZ|TIm2pA#R JB?Cub;0u^3CPV-L literal 0 HcmV?d00001 diff --git a/PairGenrator/PairGenrator.xcodeproj/project.pbxproj b/PairGenrator/PairGenrator.xcodeproj/project.pbxproj index afb5786..4503870 100644 --- a/PairGenrator/PairGenrator.xcodeproj/project.pbxproj +++ b/PairGenrator/PairGenrator.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 4E941F2E2440CAC800B8F869 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4E941F2C2440CAC800B8F869 /* LaunchScreen.storyboard */; }; 4E941F382440CB8900B8F869 /* CoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F372440CB8900B8F869 /* CoreData.swift */; }; 4E941F3A2440CBF300B8F869 /* Person+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F392440CBF300B8F869 /* Person+Convenience.swift */; }; + 4E941F3D2440CDA300B8F869 /* PersonController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F3C2440CDA300B8F869 /* PersonController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -28,6 +29,7 @@ 4E941F2F2440CAC800B8F869 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 4E941F372440CB8900B8F869 /* CoreData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreData.swift; sourceTree = ""; }; 4E941F392440CBF300B8F869 /* Person+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Person+Convenience.swift"; sourceTree = ""; }; + 4E941F3C2440CDA300B8F869 /* PersonController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -64,6 +66,7 @@ 4E941F362440CB1F00B8F869 /* Storyboard */, 4E941F272440CAC700B8F869 /* PairGenrator.xcdatamodeld */, 4E941F3B2440CC3B00B8F869 /* Model */, + 4E941F3E2440CDA800B8F869 /* ModelController */, ); path = PairGenrator; sourceTree = ""; @@ -97,6 +100,14 @@ path = Model; sourceTree = ""; }; + 4E941F3E2440CDA800B8F869 /* ModelController */ = { + isa = PBXGroup; + children = ( + 4E941F3C2440CDA300B8F869 /* PersonController.swift */, + ); + path = ModelController; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -172,6 +183,7 @@ 4E941F1F2440CAC700B8F869 /* AppDelegate.swift in Sources */, 4E941F212440CAC700B8F869 /* SceneDelegate.swift in Sources */, 4E941F3A2440CBF300B8F869 /* Person+Convenience.swift in Sources */, + 4E941F3D2440CDA300B8F869 /* PersonController.swift in Sources */, 4E941F292440CAC700B8F869 /* PairGenrator.xcdatamodeld in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/PairGenrator/PairGenrator/ModelController/PersonController.swift b/PairGenrator/PairGenrator/ModelController/PersonController.swift new file mode 100644 index 0000000..3085040 --- /dev/null +++ b/PairGenrator/PairGenrator/ModelController/PersonController.swift @@ -0,0 +1,41 @@ +// +// PersonController.swift +// PairGenrator +// +// Created by Hin Wong on 4/10/20. +// Copyright © 2020 Hin Wong. All rights reserved. +// + +import Foundation +import CoreData + +class PersonController { + + //MARK: - Properties + static let shared = PersonController() + + var persons: [Person] { + let fetchRequest: NSFetchRequest = Person.fetchRequest() + return (try? CoreDataStack.context.fetch(fetchRequest)) ?? [] + } + + //MARK: - CRUD Functions + + func createPerson(name: String) { + Person(name: name) + CoreDataStack.saveContext() + } + + func updatePerson(person: Person, name: String) { + person.name = name + CoreDataStack.saveContext() + } + + func deletePerson(person: Person) { + CoreDataStack.context.delete(person) + CoreDataStack.saveContext() + } + + //MARK: - Helper Functions + +}//End of class From b4e26be733502b364a24633f1a3ca795d4238a78 Mon Sep 17 00:00:00 2001 From: Hin Wong Date: Fri, 10 Apr 2020 10:25:03 -0600 Subject: [PATCH 3/6] helper function written --- .../ModelController/PersonController.swift | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/PairGenrator/PairGenrator/ModelController/PersonController.swift b/PairGenrator/PairGenrator/ModelController/PersonController.swift index 3085040..5b86d54 100644 --- a/PairGenrator/PairGenrator/ModelController/PersonController.swift +++ b/PairGenrator/PairGenrator/ModelController/PersonController.swift @@ -38,4 +38,25 @@ class PersonController { //MARK: - Helper Functions + //TODO: - Potential error + + func pairingUp() -> [[Person]]{ + let randomPairs = persons.shuffled() + + var pairs = [[Person]]() + var pair = [Person]() + + for person in randomPairs { + if pair.count == 0 { + pair.append(person) + } else { + pair.append(person) + pairs.append(pair) + pair = [Person]() + } + + } + return pairs + } + }//End of class From 8763dc591c49d03066006a44f1bdfabf48860b4a Mon Sep 17 00:00:00 2001 From: Hin Wong Date: Fri, 10 Apr 2020 10:59:27 -0600 Subject: [PATCH 4/6] storyboard completed --- .../PairGenrator.xcodeproj/project.pbxproj | 16 ++++ .../Storyboard/Base.lproj/Main.storyboard | 91 +++++++++++++++++-- .../PairsTableViewController.swift | 90 ++++++++++++++++++ .../PersonDetailViewController.swift | 30 ++++++ 4 files changed, 217 insertions(+), 10 deletions(-) create mode 100644 PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift create mode 100644 PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift diff --git a/PairGenrator/PairGenrator.xcodeproj/project.pbxproj b/PairGenrator/PairGenrator.xcodeproj/project.pbxproj index 4503870..d4cd3f9 100644 --- a/PairGenrator/PairGenrator.xcodeproj/project.pbxproj +++ b/PairGenrator/PairGenrator.xcodeproj/project.pbxproj @@ -16,6 +16,8 @@ 4E941F382440CB8900B8F869 /* CoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F372440CB8900B8F869 /* CoreData.swift */; }; 4E941F3A2440CBF300B8F869 /* Person+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F392440CBF300B8F869 /* Person+Convenience.swift */; }; 4E941F3D2440CDA300B8F869 /* PersonController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F3C2440CDA300B8F869 /* PersonController.swift */; }; + 4E941F402440DCF000B8F869 /* PairsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F3F2440DCF000B8F869 /* PairsTableViewController.swift */; }; + 4E941F422440DD1400B8F869 /* PersonDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E941F412440DD1400B8F869 /* PersonDetailViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -30,6 +32,8 @@ 4E941F372440CB8900B8F869 /* CoreData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreData.swift; sourceTree = ""; }; 4E941F392440CBF300B8F869 /* Person+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Person+Convenience.swift"; sourceTree = ""; }; 4E941F3C2440CDA300B8F869 /* PersonController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonController.swift; sourceTree = ""; }; + 4E941F3F2440DCF000B8F869 /* PairsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PairsTableViewController.swift; sourceTree = ""; }; + 4E941F412440DD1400B8F869 /* PersonDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonDetailViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -67,6 +71,7 @@ 4E941F272440CAC700B8F869 /* PairGenrator.xcdatamodeld */, 4E941F3B2440CC3B00B8F869 /* Model */, 4E941F3E2440CDA800B8F869 /* ModelController */, + 4E941F432440DD1C00B8F869 /* ViewController */, ); path = PairGenrator; sourceTree = ""; @@ -108,6 +113,15 @@ path = ModelController; sourceTree = ""; }; + 4E941F432440DD1C00B8F869 /* ViewController */ = { + isa = PBXGroup; + children = ( + 4E941F3F2440DCF000B8F869 /* PairsTableViewController.swift */, + 4E941F412440DD1400B8F869 /* PersonDetailViewController.swift */, + ); + path = ViewController; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -179,6 +193,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4E941F422440DD1400B8F869 /* PersonDetailViewController.swift in Sources */, + 4E941F402440DCF000B8F869 /* PairsTableViewController.swift in Sources */, 4E941F382440CB8900B8F869 /* CoreData.swift in Sources */, 4E941F1F2440CAC700B8F869 /* AppDelegate.swift in Sources */, 4E941F212440CAC700B8F869 /* SceneDelegate.swift in Sources */, diff --git a/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard b/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard index 25a7638..2b0c527 100644 --- a/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard +++ b/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard @@ -1,24 +1,95 @@ - + + - + - - + + - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift b/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift new file mode 100644 index 0000000..384fef6 --- /dev/null +++ b/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift @@ -0,0 +1,90 @@ +// +// PairsTableViewController.swift +// PairGenrator +// +// Created by Hin Wong on 4/10/20. +// Copyright © 2020 Hin Wong. All rights reserved. +// + +import UIKit + +class PairsTableViewController: UITableViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Uncomment the following line to preserve selection between presentations + // self.clearsSelectionOnViewWillAppear = false + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem + } + + // MARK: - Table view data source + + override func numberOfSections(in tableView: UITableView) -> Int { + // #warning Incomplete implementation, return the number of sections + return 0 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + // #warning Incomplete implementation, return the number of rows + return 0 + } + + /* + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) + + // Configure the cell... + + return cell + } + */ + + /* + // Override to support conditional editing of the table view. + override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { + // Return false if you do not want the specified item to be editable. + return true + } + */ + + /* + // Override to support editing the table view. + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { + if editingStyle == .delete { + // Delete the row from the data source + tableView.deleteRows(at: [indexPath], with: .fade) + } else if editingStyle == .insert { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } + } + */ + + /* + // Override to support rearranging the table view. + override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) { + + } + */ + + /* + // Override to support conditional rearranging of the table view. + override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { + // Return false if you do not want the item to be re-orderable. + return true + } + */ + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destination. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift b/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift new file mode 100644 index 0000000..6068496 --- /dev/null +++ b/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift @@ -0,0 +1,30 @@ +// +// PersonDetailViewController.swift +// PairGenrator +// +// Created by Hin Wong on 4/10/20. +// Copyright © 2020 Hin Wong. All rights reserved. +// + +import UIKit + +class PersonDetailViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destination. + // Pass the selected object to the new view controller. + } + */ + +} From 7f728d62f1de7833ecd8fa6e7f08587a1a0c7150 Mon Sep 17 00:00:00 2001 From: Hin Wong Date: Fri, 10 Apr 2020 11:24:35 -0600 Subject: [PATCH 5/6] List TVC complete --- PairGenrator/.DS_Store | Bin 6148 -> 6148 bytes .../Storyboard/Base.lproj/Main.storyboard | 19 ++- .../PairsTableViewController.swift | 114 ++++++++++-------- .../PersonDetailViewController.swift | 9 +- 4 files changed, 88 insertions(+), 54 deletions(-) diff --git a/PairGenrator/.DS_Store b/PairGenrator/.DS_Store index 9e965525095912c83c1dc9ff7995bd240d0c0f2b..dd45066c86ccc4febf94f0cf78e6d6aa4c597a2f 100644 GIT binary patch delta 128 zcmZoMXfc=|#>B)qu~2NHo+2a5#DLw47ceq1vP|Y-v}5|d6i69}B`mu~2NHo+2aD#DLwC4MbQbPiE4cY{SIIbn(vQ2}}n31sR6H$@#ej u3?RTLuvwA$8Ovq^=4p(Z**W+*fck+V- - + @@ -24,7 +24,7 @@ - + @@ -34,8 +34,16 @@ - - + + + + + + + + + + @@ -68,6 +76,9 @@ + + + diff --git a/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift b/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift index 384fef6..6b8c2fb 100644 --- a/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift +++ b/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift @@ -9,82 +9,100 @@ import UIKit class PairsTableViewController: UITableViewController { + + //MARK: - Properties + var pairs: [[Person]]? override func viewDidLoad() { super.viewDidLoad() - - // Uncomment the following line to preserve selection between presentations - // self.clearsSelectionOnViewWillAppear = false - - // Uncomment the following line to display an Edit button in the navigation bar for this view controller. - // self.navigationItem.rightBarButtonItem = self.editButtonItem } - + + //MARK: - Actions + @IBAction func pairUpButtonTapped(_ sender: Any) { + generatePairs() + } + + @IBAction func addButtonTapped(_ sender: Any) { + let alertController = UIAlertController(title: "Add Person Please", message: "Add a person to the list.", preferredStyle: .alert) + alertController.addTextField { textField in + textField.placeholder = "Full Name" + textField.autocapitalizationType = .words + textField.autocorrectionType = .no + } + let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) + let addAction = UIAlertAction(title: "Add", style: .default) { _ in + + guard let name = alertController.textFields?.first?.text, !name.isEmpty else { + self.present(alertController, animated: true) + return + } + + PersonController.shared.createPerson(name: name) + self.generatePairs() + } + alertController.addAction(cancelAction) + alertController.addAction(addAction) + present(alertController, animated: true) + } + + //MARK: - Helper functions + + func generatePairs() { + pairs = PersonController.shared.pairingUp() + tableView.reloadData() + } + // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { // #warning Incomplete implementation, return the number of sections - return 0 + return pairs?.count ?? 0 + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + return "Pair \(section + 1)" } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - // #warning Incomplete implementation, return the number of rows - return 0 + return pairs?[section].count ?? 0 } - /* + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) + let cell = tableView.dequeueReusableCell(withIdentifier: "pairCell", for: indexPath) - // Configure the cell... + let person = pairs?[indexPath.section][indexPath.row] + cell.textLabel?.text = person?.name return cell } - */ - /* - // Override to support conditional editing of the table view. - override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { - // Return false if you do not want the specified item to be editable. - return true - } - */ - - /* - // Override to support editing the table view. override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { - // Delete the row from the data source + guard let person = pairs?[indexPath.section][indexPath.row] else {return} + + pairs?[indexPath.section].remove(at: indexPath.row) + PersonController.shared.deletePerson(person: person) + tableView.deleteRows(at: [indexPath], with: .fade) - } else if editingStyle == .insert { - // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view - } - } - */ - - /* - // Override to support rearranging the table view. - override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) { - - } - */ - - /* - // Override to support conditional rearranging of the table view. - override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { - // Return false if you do not want the item to be re-orderable. - return true + } } - */ - /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + + if segue.identifier == "toPersonDetailVC" { + guard let indexPath = tableView.indexPathForSelectedRow, + let destination = segue.destination as? PersonDetailViewController + else { + print("Cannot segue to details view") + return} + + destination.person = pairs?[indexPath.section][indexPath.row] + } } - */ + } diff --git a/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift b/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift index 6068496..5c2b722 100644 --- a/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift +++ b/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift @@ -9,11 +9,16 @@ import UIKit class PersonDetailViewController: UIViewController { + + //MARK: - Properties + var person: Person? + + //MARK: - Outlets + @IBOutlet weak var nameTextField: UITextField! + override func viewDidLoad() { super.viewDidLoad() - - // Do any additional setup after loading the view. } From e6ea48e8140467535ba865e94b4e9181c9f7b071 Mon Sep 17 00:00:00 2001 From: Hin Wong Date: Fri, 10 Apr 2020 11:41:31 -0600 Subject: [PATCH 6/6] project completed --- PairGenrator/.DS_Store | Bin 6148 -> 6148 bytes .../PairGenrator/Model/CoreData.swift | 2 +- .../ModelController/PersonController.swift | 5 +++ .../Storyboard/Base.lproj/Main.storyboard | 14 +++++--- .../PairsTableViewController.swift | 8 ++++- .../PersonDetailViewController.swift | 30 +++++++++++------- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/PairGenrator/.DS_Store b/PairGenrator/.DS_Store index dd45066c86ccc4febf94f0cf78e6d6aa4c597a2f..6c2ebba71b607bd3879a09e88388de1f768d8e46 100644 GIT binary patch delta 19 acmZoMXffE}#l-Zhc=7}$qs?_pZK423PzLz` delta 19 acmZoMXffE}#l-Y|>EsDaMw{!H+C%|LBL^q| diff --git a/PairGenrator/PairGenrator/Model/CoreData.swift b/PairGenrator/PairGenrator/Model/CoreData.swift index 70ff0e8..6280f74 100644 --- a/PairGenrator/PairGenrator/Model/CoreData.swift +++ b/PairGenrator/PairGenrator/Model/CoreData.swift @@ -13,7 +13,7 @@ enum CoreDataStack { //MARK: - Core data stack static let container: NSPersistentContainer = { - let container = NSPersistentContainer(name: "PlaylistCoreData") + let container = NSPersistentContainer(name: "PairGenrator") container.loadPersistentStores { (_, error) in if let error = error { fatalError("Failed to load persistet stores \(error)") diff --git a/PairGenrator/PairGenrator/ModelController/PersonController.swift b/PairGenrator/PairGenrator/ModelController/PersonController.swift index 5b86d54..3c405b1 100644 --- a/PairGenrator/PairGenrator/ModelController/PersonController.swift +++ b/PairGenrator/PairGenrator/ModelController/PersonController.swift @@ -56,6 +56,11 @@ class PersonController { } } + + if pair.count != 0 { + pairs.append(pair) + } + return pairs } diff --git a/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard b/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard index cbeb025..898fb65 100644 --- a/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard +++ b/PairGenrator/PairGenrator/Storyboard/Base.lproj/Main.storyboard @@ -7,7 +7,7 @@ - + @@ -33,7 +33,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -73,8 +73,12 @@ - - + + + + + + diff --git a/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift b/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift index 6b8c2fb..ad8877f 100644 --- a/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift +++ b/PairGenrator/PairGenrator/ViewController/PairsTableViewController.swift @@ -13,8 +13,15 @@ class PairsTableViewController: UITableViewController { //MARK: - Properties var pairs: [[Person]]? + //MARK: - Life Cycle override func viewDidLoad() { super.viewDidLoad() + generatePairs() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + tableView.reloadData() } //MARK: - Actions @@ -67,7 +74,6 @@ class PairsTableViewController: UITableViewController { return pairs?[section].count ?? 0 } - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "pairCell", for: indexPath) diff --git a/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift b/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift index 5c2b722..4329a5e 100644 --- a/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift +++ b/PairGenrator/PairGenrator/ViewController/PersonDetailViewController.swift @@ -15,21 +15,29 @@ class PersonDetailViewController: UIViewController { //MARK: - Outlets @IBOutlet weak var nameTextField: UITextField! - + //MARK: - Life Cycle override func viewDidLoad() { super.viewDidLoad() + + if let person = person { + nameTextField.text = person.name + } + } + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + nameTextField.becomeFirstResponder() } - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + //MARK: - Actions + + @IBAction func saveButtonTapped(_ sender: Any) { + guard let newName = nameTextField.text, !newName.isEmpty, + let person = person + else { return } + + PersonController.shared.updatePerson(person: person, name: newName) + navigationController?.popViewController(animated: true) } - */ - + }