diff --git a/StudentPairs/StudentPairs.xcodeproj/project.pbxproj b/StudentPairs/StudentPairs.xcodeproj/project.pbxproj new file mode 100644 index 0000000..28495f9 --- /dev/null +++ b/StudentPairs/StudentPairs.xcodeproj/project.pbxproj @@ -0,0 +1,424 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 505F369224817D870048C2A8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505F369124817D870048C2A8 /* AppDelegate.swift */; }; + 505F369524817D870048C2A8 /* StudentPairs.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 505F369324817D870048C2A8 /* StudentPairs.xcdatamodeld */; }; + 505F369724817D870048C2A8 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505F369624817D870048C2A8 /* SceneDelegate.swift */; }; + 505F369E24817D870048C2A8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 505F369C24817D870048C2A8 /* Main.storyboard */; }; + 505F36A024817D890048C2A8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 505F369F24817D890048C2A8 /* Assets.xcassets */; }; + 505F36A324817D8A0048C2A8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 505F36A124817D890048C2A8 /* LaunchScreen.storyboard */; }; + 505F36B124817E6D0048C2A8 /* StudentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505F36B024817E6D0048C2A8 /* StudentController.swift */; }; + 505F36B324817E7D0048C2A8 /* StudentDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505F36B224817E7D0048C2A8 /* StudentDetailViewController.swift */; }; + 505F36B524817E8E0048C2A8 /* StudentsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505F36B424817E8E0048C2A8 /* StudentsTableViewController.swift */; }; + 505F36B724817EA70048C2A8 /* CoreDataStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505F36B624817EA70048C2A8 /* CoreDataStack.swift */; }; + 505F36B924817EB60048C2A8 /* Student+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505F36B824817EB60048C2A8 /* Student+Convenience.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 505F368E24817D870048C2A8 /* StudentPairs.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StudentPairs.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 505F369124817D870048C2A8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 505F369424817D870048C2A8 /* StudentPairs.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = StudentPairs.xcdatamodel; sourceTree = ""; }; + 505F369624817D870048C2A8 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 505F369D24817D870048C2A8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 505F369F24817D890048C2A8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 505F36A224817D890048C2A8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 505F36A424817D8A0048C2A8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 505F36B024817E6D0048C2A8 /* StudentController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudentController.swift; sourceTree = ""; }; + 505F36B224817E7D0048C2A8 /* StudentDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudentDetailViewController.swift; sourceTree = ""; }; + 505F36B424817E8E0048C2A8 /* StudentsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudentsTableViewController.swift; sourceTree = ""; }; + 505F36B624817EA70048C2A8 /* CoreDataStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataStack.swift; sourceTree = ""; }; + 505F36B824817EB60048C2A8 /* Student+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Student+Convenience.swift"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 505F368B24817D870048C2A8 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 505F368524817D870048C2A8 = { + isa = PBXGroup; + children = ( + 505F369024817D870048C2A8 /* StudentPairs */, + 505F368F24817D870048C2A8 /* Products */, + ); + sourceTree = ""; + }; + 505F368F24817D870048C2A8 /* Products */ = { + isa = PBXGroup; + children = ( + 505F368E24817D870048C2A8 /* StudentPairs.app */, + ); + name = Products; + sourceTree = ""; + }; + 505F369024817D870048C2A8 /* StudentPairs */ = { + isa = PBXGroup; + children = ( + 505F36AB24817E0A0048C2A8 /* Models */, + 505F36AC24817E0F0048C2A8 /* StoryboardViews */, + 505F36AD24817E180048C2A8 /* Controllers */, + 505F36AA24817D910048C2A8 /* Resources */, + ); + path = StudentPairs; + sourceTree = ""; + }; + 505F36AA24817D910048C2A8 /* Resources */ = { + isa = PBXGroup; + children = ( + 505F369124817D870048C2A8 /* AppDelegate.swift */, + 505F369624817D870048C2A8 /* SceneDelegate.swift */, + 505F369F24817D890048C2A8 /* Assets.xcassets */, + 505F36A124817D890048C2A8 /* LaunchScreen.storyboard */, + 505F36A424817D8A0048C2A8 /* Info.plist */, + ); + path = Resources; + sourceTree = ""; + }; + 505F36AB24817E0A0048C2A8 /* Models */ = { + isa = PBXGroup; + children = ( + 505F369324817D870048C2A8 /* StudentPairs.xcdatamodeld */, + 505F36B824817EB60048C2A8 /* Student+Convenience.swift */, + 505F36B624817EA70048C2A8 /* CoreDataStack.swift */, + ); + path = Models; + sourceTree = ""; + }; + 505F36AC24817E0F0048C2A8 /* StoryboardViews */ = { + isa = PBXGroup; + children = ( + 505F369C24817D870048C2A8 /* Main.storyboard */, + ); + path = StoryboardViews; + sourceTree = ""; + }; + 505F36AD24817E180048C2A8 /* Controllers */ = { + isa = PBXGroup; + children = ( + 505F36AF24817E2E0048C2A8 /* ModelControllers */, + 505F36AE24817E270048C2A8 /* ViewControllers */, + ); + path = Controllers; + sourceTree = ""; + }; + 505F36AE24817E270048C2A8 /* ViewControllers */ = { + isa = PBXGroup; + children = ( + 505F36B424817E8E0048C2A8 /* StudentsTableViewController.swift */, + 505F36B224817E7D0048C2A8 /* StudentDetailViewController.swift */, + ); + path = ViewControllers; + sourceTree = ""; + }; + 505F36AF24817E2E0048C2A8 /* ModelControllers */ = { + isa = PBXGroup; + children = ( + 505F36B024817E6D0048C2A8 /* StudentController.swift */, + ); + path = ModelControllers; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 505F368D24817D870048C2A8 /* StudentPairs */ = { + isa = PBXNativeTarget; + buildConfigurationList = 505F36A724817D8A0048C2A8 /* Build configuration list for PBXNativeTarget "StudentPairs" */; + buildPhases = ( + 505F368A24817D870048C2A8 /* Sources */, + 505F368B24817D870048C2A8 /* Frameworks */, + 505F368C24817D870048C2A8 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = StudentPairs; + productName = StudentPairs; + productReference = 505F368E24817D870048C2A8 /* StudentPairs.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 505F368624817D870048C2A8 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1150; + LastUpgradeCheck = 1150; + ORGANIZATIONNAME = AaronPrestidge; + TargetAttributes = { + 505F368D24817D870048C2A8 = { + CreatedOnToolsVersion = 11.5; + }; + }; + }; + buildConfigurationList = 505F368924817D870048C2A8 /* Build configuration list for PBXProject "StudentPairs" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 505F368524817D870048C2A8; + productRefGroup = 505F368F24817D870048C2A8 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 505F368D24817D870048C2A8 /* StudentPairs */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 505F368C24817D870048C2A8 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 505F36A324817D8A0048C2A8 /* LaunchScreen.storyboard in Resources */, + 505F36A024817D890048C2A8 /* Assets.xcassets in Resources */, + 505F369E24817D870048C2A8 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 505F368A24817D870048C2A8 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 505F36B724817EA70048C2A8 /* CoreDataStack.swift in Sources */, + 505F369224817D870048C2A8 /* AppDelegate.swift in Sources */, + 505F36B124817E6D0048C2A8 /* StudentController.swift in Sources */, + 505F36B924817EB60048C2A8 /* Student+Convenience.swift in Sources */, + 505F36B324817E7D0048C2A8 /* StudentDetailViewController.swift in Sources */, + 505F36B524817E8E0048C2A8 /* StudentsTableViewController.swift in Sources */, + 505F369524817D870048C2A8 /* StudentPairs.xcdatamodeld in Sources */, + 505F369724817D870048C2A8 /* SceneDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 505F369C24817D870048C2A8 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 505F369D24817D870048C2A8 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 505F36A124817D890048C2A8 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 505F36A224817D890048C2A8 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 505F36A524817D8A0048C2A8 /* 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.5; + 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; + }; + 505F36A624817D8A0048C2A8 /* 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.5; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 505F36A824817D8A0048C2A8 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 6XG2KXXAH9; + INFOPLIST_FILE = StudentPairs/Resources/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = AaronPrestidge.StudentPairs; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 505F36A924817D8A0048C2A8 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 6XG2KXXAH9; + INFOPLIST_FILE = StudentPairs/Resources/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = AaronPrestidge.StudentPairs; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 505F368924817D870048C2A8 /* Build configuration list for PBXProject "StudentPairs" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 505F36A524817D8A0048C2A8 /* Debug */, + 505F36A624817D8A0048C2A8 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 505F36A724817D8A0048C2A8 /* Build configuration list for PBXNativeTarget "StudentPairs" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 505F36A824817D8A0048C2A8 /* Debug */, + 505F36A924817D8A0048C2A8 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + 505F369324817D870048C2A8 /* StudentPairs.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + 505F369424817D870048C2A8 /* StudentPairs.xcdatamodel */, + ); + currentVersion = 505F369424817D870048C2A8 /* StudentPairs.xcdatamodel */; + path = StudentPairs.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ + }; + rootObject = 505F368624817D870048C2A8 /* Project object */; +} diff --git a/StudentPairs/StudentPairs.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/StudentPairs/StudentPairs.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..44377d4 --- /dev/null +++ b/StudentPairs/StudentPairs.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/StudentPairs/StudentPairs.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/StudentPairs/StudentPairs.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/StudentPairs/StudentPairs.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/StudentPairs/StudentPairs/Controllers/ModelControllers/StudentController.swift b/StudentPairs/StudentPairs/Controllers/ModelControllers/StudentController.swift new file mode 100644 index 0000000..a8ad66b --- /dev/null +++ b/StudentPairs/StudentPairs/Controllers/ModelControllers/StudentController.swift @@ -0,0 +1,83 @@ +// +// StudentController.swift +// StudentPairs +// +// Created by Aaron Prestidge on 5/29/20. +// Copyright © 2020 AaronPrestidge. All rights reserved. +// + +import CoreData +import Foundation + +class StudentController { + + //MARK: - Shared Instance + static let shared = StudentController() + + //MARK: - Properties + var students: [Student] { + let request: NSFetchRequest = Student.fetchRequest() + let result = try? CoreDataStack.context.fetch(request) + print("Students array set") + return result ?? [] + } + + var pairs: [[Student]] = [] + + //MARK: - Helper Methods + func shuffle() { + var tempStudents: [Student] = [] + var tempPairs: [[Student]] = [] + for student in students.shuffled() { + if tempStudents.count < 2 { + tempStudents.append(student) + print("Student added to temporary array of students") + } else if tempStudents.count == 2 { + tempPairs.append(tempStudents) + print("Student pair added to temporary array of pairs") + tempStudents = [] + print("Temp student array emptied") + tempStudents.append(student) + print("Student added to temp students array") + } + } + if tempStudents.count > 0 { + tempPairs.append(tempStudents) + print("Student pair added to temporary array of pairs") + } + pairs = tempPairs + print("Pairs property set equal to tempPairs array.") + } + + //MARK: - CoreData Persistence + private func saveToPersistentStore() { + let mOC = CoreDataStack.context + do { + try mOC.save() + print("Data saved to CoreData") + } catch { + print("Error saving to CoreData: \(error.localizedDescription)") + } + } + + //MARK: - CRUD Functions + func create(from name: String) { + let _ = Student(name: name) + print("New student created") + saveToPersistentStore() + } + + func update(with student: Student, and name: String) { + student.name = name + print("Student has been updated") + saveToPersistentStore() + } + + func delete(student: Student) { + CoreDataStack.context.delete(student) + print("Student has been deleted") + saveToPersistentStore() + } + + +}//End Class diff --git a/StudentPairs/StudentPairs/Controllers/ViewControllers/StudentDetailViewController.swift b/StudentPairs/StudentPairs/Controllers/ViewControllers/StudentDetailViewController.swift new file mode 100644 index 0000000..0c0be18 --- /dev/null +++ b/StudentPairs/StudentPairs/Controllers/ViewControllers/StudentDetailViewController.swift @@ -0,0 +1,50 @@ +// +// StudentDetailViewController.swift +// Randomizer +// +// Created by Aaron Prestidge on 5/28/20. +// Copyright © 2020 AaronPrestidge. All rights reserved. +// + +import UIKit + +class StudentDetailViewController: UIViewController { + + //MARK: - Properties + var student: Student? { + didSet { + self.loadViewIfNeeded() + } + } + + //MARK: - Outlets + @IBOutlet weak var nameTextField: UITextField! + + //MARK: - Lifecycle + override func viewDidLoad() { + super.viewDidLoad() + + if let student = student { + nameTextField.text = student.name + } + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + nameTextField.becomeFirstResponder() + } + + //MARK: - Actions + @IBAction func saveButtonTapped(_ sender: UIButton) { + guard let name = self.nameTextField.text, + let student = self.student else { return } + StudentController.shared.update(with: student, and: name) + navigationController?.popViewController(animated: true) + + } + + @IBAction func cancelButtonTapped(_ sender: UIBarButtonItem) { + navigationController?.popViewController(animated: true) + } + +}//End Class diff --git a/StudentPairs/StudentPairs/Controllers/ViewControllers/StudentsTableViewController.swift b/StudentPairs/StudentPairs/Controllers/ViewControllers/StudentsTableViewController.swift new file mode 100644 index 0000000..e17efea --- /dev/null +++ b/StudentPairs/StudentPairs/Controllers/ViewControllers/StudentsTableViewController.swift @@ -0,0 +1,125 @@ +// +// StudentsTableViewController.swift +// StudentPairs +// +// Created by Aaron Prestidge on 5/29/20. +// Copyright © 2020 AaronPrestidge. All rights reserved. +// + +import UIKit + +class StudentsTableViewController: UITableViewController { + + // MARK: - Lifecycle + override func viewDidLoad() { + super.viewDidLoad() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + StudentController.shared.shuffle() + tableView.reloadData() + } + + // MARK: - Actions + @IBAction func addButtonTapped(_ sender: UIBarButtonItem) { + presentAddStudentAlert() + tableView.reloadData() + print("Add student alert controller presented, table view reloaded") + } + + @IBAction func shuffleButtonTapped(_ sender: UIBarButtonItem) { + StudentController.shared.shuffle() + tableView.reloadData() + print("Student pairs shuffled, table view reloaded") + } + + // MARK: - Methods + func presentAddStudentAlert() { + let alertController = UIAlertController(title: "Add Student", message: "Add a new student to the list", preferredStyle: .alert) + var newStudentTextField: UITextField? + alertController.addTextField { (alertTextField) in + alertTextField.placeholder = "Enter name..." + newStudentTextField = alertTextField + } + let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) + let addAction = UIAlertAction(title: "Add", style: .default) { (_) in + guard let inputText = newStudentTextField?.text else { return } + StudentController.shared.create(from: inputText) + StudentController.shared.shuffle() + self.tableView.reloadData() + } + alertController.addAction(cancelAction) + alertController.addAction(addAction) + present(alertController, animated: true, completion: nil) + } + + // MARK: - Table view data source + override func numberOfSections(in tableView: UITableView) -> Int { + return StudentController.shared.pairs.count + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + return "Pair \(section + 1)" + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return StudentController.shared.pairs[section].count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "studentCell", for: indexPath) + let pair = StudentController.shared.pairs[indexPath.section] + let student = pair[indexPath.row] + cell.textLabel?.text = student.name + return cell + } + + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { + if editingStyle == .delete { + let student = StudentController.shared.pairs[indexPath.section][indexPath.row] + StudentController.shared.pairs[indexPath.section].remove(at: indexPath.row) + StudentController.shared.delete(student: student) + tableView.deleteRows(at: [indexPath], with: .fade) + StudentController.shared.shuffle() + tableView.reloadData() + } + } + + // MARK: - Navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.identifier == "toUpdateVC" { + guard let indexPath = tableView.indexPathForSelectedRow, + let destination = segue.destination as? StudentDetailViewController else { return } + destination.student = StudentController.shared.pairs[indexPath.section][indexPath.row] + } + } + +}//End Class + +@IBDesignable extension UIButton { + @IBInspectable var borderWidth: CGFloat { + set { + layer.borderWidth = newValue + } get { + return layer.borderWidth + } + } + + @IBInspectable var cornerRadius: CGFloat { + set { + layer.cornerRadius = newValue } + get { + return layer.cornerRadius } + } + + @IBInspectable var borderColor: UIColor? { + set { + guard let uiColor = newValue else { return } + layer.borderColor = uiColor.cgColor + } get { + guard let color = layer.borderColor else { return nil } + return UIColor(cgColor: color) + } + } +}//End Extension diff --git a/StudentPairs/StudentPairs/Models/CoreDataStack.swift b/StudentPairs/StudentPairs/Models/CoreDataStack.swift new file mode 100644 index 0000000..a161b8c --- /dev/null +++ b/StudentPairs/StudentPairs/Models/CoreDataStack.swift @@ -0,0 +1,28 @@ +// +// CoreDataStack.swift +// StudentPairs +// +// Created by Aaron Prestidge on 5/29/20. +// Copyright © 2020 AaronPrestidge. All rights reserved. +// + +import CoreData +import Foundation + +enum CoreDataStack { + + static let container: NSPersistentContainer = { + + let appName = Bundle.main.object(forInfoDictionaryKey: (kCFBundleNameKey as String)) as! String + let container = NSPersistentContainer(name: appName) + container.loadPersistentStores() { (_, error) in + if let error = error as NSError? { + fatalError("Unresolved error \(error), \(error.userInfo)") + } + } + return container + }() + + static var context: NSManagedObjectContext { return container.viewContext } + +}//End enum diff --git a/StudentPairs/StudentPairs/Models/Student+Convenience.swift b/StudentPairs/StudentPairs/Models/Student+Convenience.swift new file mode 100644 index 0000000..2e948ab --- /dev/null +++ b/StudentPairs/StudentPairs/Models/Student+Convenience.swift @@ -0,0 +1,20 @@ +// +// Student+Convenience.swift +// StudentPairs +// +// Created by Aaron Prestidge on 5/29/20. +// Copyright © 2020 AaronPrestidge. All rights reserved. +// + +import CoreData +import Foundation + +extension Student { + + @discardableResult + convenience init(name: String, moc: NSManagedObjectContext = CoreDataStack.context) { + self.init(context: moc) + self.name = name + } + +}//End Ext diff --git a/StudentPairs/StudentPairs/Models/StudentPairs.xcdatamodeld/.xccurrentversion b/StudentPairs/StudentPairs/Models/StudentPairs.xcdatamodeld/.xccurrentversion new file mode 100644 index 0000000..703eaaf --- /dev/null +++ b/StudentPairs/StudentPairs/Models/StudentPairs.xcdatamodeld/.xccurrentversion @@ -0,0 +1,8 @@ + + + + + _XCCurrentVersionName + StudentPairs.xcdatamodel + + diff --git a/StudentPairs/StudentPairs/Models/StudentPairs.xcdatamodeld/StudentPairs.xcdatamodel/contents b/StudentPairs/StudentPairs/Models/StudentPairs.xcdatamodeld/StudentPairs.xcdatamodel/contents new file mode 100644 index 0000000..40185a4 --- /dev/null +++ b/StudentPairs/StudentPairs/Models/StudentPairs.xcdatamodeld/StudentPairs.xcdatamodel/contents @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/StudentPairs/StudentPairs/Resources/AppDelegate.swift b/StudentPairs/StudentPairs/Resources/AppDelegate.swift new file mode 100644 index 0000000..0805dfd --- /dev/null +++ b/StudentPairs/StudentPairs/Resources/AppDelegate.swift @@ -0,0 +1,82 @@ +// +// AppDelegate.swift +// StudentPairs +// +// Created by Aaron Prestidge on 5/29/20. +// Copyright © 2020 AaronPrestidge. 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: "StudentPairs") + 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/StudentPairs/StudentPairs/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json b/StudentPairs/StudentPairs/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..9221b9b --- /dev/null +++ b/StudentPairs/StudentPairs/Resources/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/StudentPairs/StudentPairs/Resources/Assets.xcassets/Contents.json b/StudentPairs/StudentPairs/Resources/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/StudentPairs/StudentPairs/Resources/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/StudentPairs/StudentPairs/Resources/Base.lproj/LaunchScreen.storyboard b/StudentPairs/StudentPairs/Resources/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/StudentPairs/StudentPairs/Resources/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StudentPairs/StudentPairs/Resources/Info.plist b/StudentPairs/StudentPairs/Resources/Info.plist new file mode 100644 index 0000000..e7f6f58 --- /dev/null +++ b/StudentPairs/StudentPairs/Resources/Info.plist @@ -0,0 +1,74 @@ + + + + + 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 + + UIStatusBarTintParameters + + UINavigationBar + + Style + UIBarStyleDefault + Translucent + + + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/StudentPairs/StudentPairs/Resources/SceneDelegate.swift b/StudentPairs/StudentPairs/Resources/SceneDelegate.swift new file mode 100644 index 0000000..524f4f6 --- /dev/null +++ b/StudentPairs/StudentPairs/Resources/SceneDelegate.swift @@ -0,0 +1,57 @@ +// +// SceneDelegate.swift +// Randomizer +// +// Created by Aaron Prestidge on 5/28/20. +// Copyright © 2020 AaronPrestidge. 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() + } + + +} + + \ No newline at end of file diff --git a/StudentPairs/StudentPairs/StoryboardViews/Base.lproj/Main.storyboard b/StudentPairs/StudentPairs/StoryboardViews/Base.lproj/Main.storyboard new file mode 100644 index 0000000..e9310b3 --- /dev/null +++ b/StudentPairs/StudentPairs/StoryboardViews/Base.lproj/Main.storyboard @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +