diff --git a/.gitignore b/.gitignore index 7e4c35d1b..595b42373 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,117 @@ -# See https://help.github.com/ignore-files/ for more about ignoring files. -# dependencies -**/node_modules +# Created by https://www.toptal.com/developers/gitignore/api/swift,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=swift,macos -# testing -/coverage +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride -# production -/build +# Icon must end with two \r +Icon -# misc -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local - -**npm-debug.log* -**yarn-debug.log* -**yarn-error.log* -**yarn.lock +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Swift ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ + +# CocoaPods +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# Pods/ +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + +# End of https://www.toptal.com/developers/gitignore/api/swift,macos \ No newline at end of file diff --git a/GameOfLife/GameOfLife.xcodeproj/project.pbxproj b/GameOfLife/GameOfLife.xcodeproj/project.pbxproj new file mode 100644 index 000000000..72d099d0d --- /dev/null +++ b/GameOfLife/GameOfLife.xcodeproj/project.pbxproj @@ -0,0 +1,627 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + BA4321E124CF420600D6B7D0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4321E024CF420600D6B7D0 /* AppDelegate.swift */; }; + BA4321E324CF420600D6B7D0 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4321E224CF420600D6B7D0 /* SceneDelegate.swift */; }; + BA4321E524CF420600D6B7D0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4321E424CF420600D6B7D0 /* ViewController.swift */; }; + BA4321E824CF420600D6B7D0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BA4321E624CF420600D6B7D0 /* Main.storyboard */; }; + BA4321ED24CF420700D6B7D0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BA4321EC24CF420700D6B7D0 /* Assets.xcassets */; }; + BA4321F024CF420700D6B7D0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BA4321EE24CF420700D6B7D0 /* LaunchScreen.storyboard */; }; + BA4321FB24CF420700D6B7D0 /* GameOfLifeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4321FA24CF420700D6B7D0 /* GameOfLifeTests.swift */; }; + BA43220624CF420700D6B7D0 /* GameOfLifeUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA43220524CF420700D6B7D0 /* GameOfLifeUITests.swift */; }; + BA43221A24CF77A700D6B7D0 /* CellGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA43221924CF77A700D6B7D0 /* CellGridView.swift */; }; + BA43221C24CF77FB00D6B7D0 /* Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA43221B24CF77FB00D6B7D0 /* Cell.swift */; }; + BA45D3DD24D373FC00648F91 /* Sky.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = BA45D3DC24D373FC00648F91 /* Sky.mp3 */; }; + BA54CBE324D086A9008FE187 /* GridWorld.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA54CBE224D086A9008FE187 /* GridWorld.swift */; }; + BA54CBE524D0CF9A008FE187 /* GameRulesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA54CBE424D0CF9A008FE187 /* GameRulesViewController.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + BA4321F724CF420700D6B7D0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = BA4321D524CF420600D6B7D0 /* Project object */; + proxyType = 1; + remoteGlobalIDString = BA4321DC24CF420600D6B7D0; + remoteInfo = GameOfLife; + }; + BA43220224CF420700D6B7D0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = BA4321D524CF420600D6B7D0 /* Project object */; + proxyType = 1; + remoteGlobalIDString = BA4321DC24CF420600D6B7D0; + remoteInfo = GameOfLife; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + BA4321DD24CF420600D6B7D0 /* GameOfLife.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GameOfLife.app; sourceTree = BUILT_PRODUCTS_DIR; }; + BA4321E024CF420600D6B7D0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + BA4321E224CF420600D6B7D0 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + BA4321E424CF420600D6B7D0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + BA4321E724CF420600D6B7D0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + BA4321EC24CF420700D6B7D0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + BA4321EF24CF420700D6B7D0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + BA4321F124CF420700D6B7D0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + BA4321F624CF420700D6B7D0 /* GameOfLifeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GameOfLifeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + BA4321FA24CF420700D6B7D0 /* GameOfLifeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameOfLifeTests.swift; sourceTree = ""; }; + BA4321FC24CF420700D6B7D0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + BA43220124CF420700D6B7D0 /* GameOfLifeUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GameOfLifeUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + BA43220524CF420700D6B7D0 /* GameOfLifeUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameOfLifeUITests.swift; sourceTree = ""; }; + BA43220724CF420700D6B7D0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + BA43221324CF429C00D6B7D0 /* game-of-life-iOS-mock-1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "game-of-life-iOS-mock-1.png"; path = "../resources/ios/game-of-life-iOS-mock-1.png"; sourceTree = ""; }; + BA43221424CF42A200D6B7D0 /* game-of-life-iOS-mock-2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "game-of-life-iOS-mock-2.png"; path = "../resources/ios/game-of-life-iOS-mock-2.png"; sourceTree = ""; }; + BA43221924CF77A700D6B7D0 /* CellGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellGridView.swift; sourceTree = ""; }; + BA43221B24CF77FB00D6B7D0 /* Cell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cell.swift; sourceTree = ""; }; + BA45D3DC24D373FC00648F91 /* Sky.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = Sky.mp3; sourceTree = ""; }; + BA54CBE224D086A9008FE187 /* GridWorld.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridWorld.swift; sourceTree = ""; }; + BA54CBE424D0CF9A008FE187 /* GameRulesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameRulesViewController.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + BA4321DA24CF420600D6B7D0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + BA4321F324CF420700D6B7D0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + BA4321FE24CF420700D6B7D0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + BA4321D424CF420600D6B7D0 = { + isa = PBXGroup; + children = ( + BA43221324CF429C00D6B7D0 /* game-of-life-iOS-mock-1.png */, + BA43221424CF42A200D6B7D0 /* game-of-life-iOS-mock-2.png */, + BA4321DF24CF420600D6B7D0 /* GameOfLife */, + BA4321F924CF420700D6B7D0 /* GameOfLifeTests */, + BA43220424CF420700D6B7D0 /* GameOfLifeUITests */, + BA4321DE24CF420600D6B7D0 /* Products */, + ); + sourceTree = ""; + }; + BA4321DE24CF420600D6B7D0 /* Products */ = { + isa = PBXGroup; + children = ( + BA4321DD24CF420600D6B7D0 /* GameOfLife.app */, + BA4321F624CF420700D6B7D0 /* GameOfLifeTests.xctest */, + BA43220124CF420700D6B7D0 /* GameOfLifeUITests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + BA4321DF24CF420600D6B7D0 /* GameOfLife */ = { + isa = PBXGroup; + children = ( + BA45D3DC24D373FC00648F91 /* Sky.mp3 */, + BA4321E024CF420600D6B7D0 /* AppDelegate.swift */, + BA4321E224CF420600D6B7D0 /* SceneDelegate.swift */, + BA4321E424CF420600D6B7D0 /* ViewController.swift */, + BA54CBE424D0CF9A008FE187 /* GameRulesViewController.swift */, + BA43221D24CF7A0300D6B7D0 /* Model */, + BA43221924CF77A700D6B7D0 /* CellGridView.swift */, + BA4321E624CF420600D6B7D0 /* Main.storyboard */, + BA4321EC24CF420700D6B7D0 /* Assets.xcassets */, + BA4321EE24CF420700D6B7D0 /* LaunchScreen.storyboard */, + BA4321F124CF420700D6B7D0 /* Info.plist */, + ); + path = GameOfLife; + sourceTree = ""; + }; + BA4321F924CF420700D6B7D0 /* GameOfLifeTests */ = { + isa = PBXGroup; + children = ( + BA4321FA24CF420700D6B7D0 /* GameOfLifeTests.swift */, + BA4321FC24CF420700D6B7D0 /* Info.plist */, + ); + path = GameOfLifeTests; + sourceTree = ""; + }; + BA43220424CF420700D6B7D0 /* GameOfLifeUITests */ = { + isa = PBXGroup; + children = ( + BA43220524CF420700D6B7D0 /* GameOfLifeUITests.swift */, + BA43220724CF420700D6B7D0 /* Info.plist */, + ); + path = GameOfLifeUITests; + sourceTree = ""; + }; + BA43221D24CF7A0300D6B7D0 /* Model */ = { + isa = PBXGroup; + children = ( + BA43221B24CF77FB00D6B7D0 /* Cell.swift */, + BA54CBE224D086A9008FE187 /* GridWorld.swift */, + ); + path = Model; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + BA4321DC24CF420600D6B7D0 /* GameOfLife */ = { + isa = PBXNativeTarget; + buildConfigurationList = BA43220A24CF420700D6B7D0 /* Build configuration list for PBXNativeTarget "GameOfLife" */; + buildPhases = ( + BA4321D924CF420600D6B7D0 /* Sources */, + BA4321DA24CF420600D6B7D0 /* Frameworks */, + BA4321DB24CF420600D6B7D0 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = GameOfLife; + productName = GameOfLife; + productReference = BA4321DD24CF420600D6B7D0 /* GameOfLife.app */; + productType = "com.apple.product-type.application"; + }; + BA4321F524CF420700D6B7D0 /* GameOfLifeTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = BA43220D24CF420700D6B7D0 /* Build configuration list for PBXNativeTarget "GameOfLifeTests" */; + buildPhases = ( + BA4321F224CF420700D6B7D0 /* Sources */, + BA4321F324CF420700D6B7D0 /* Frameworks */, + BA4321F424CF420700D6B7D0 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + BA4321F824CF420700D6B7D0 /* PBXTargetDependency */, + ); + name = GameOfLifeTests; + productName = GameOfLifeTests; + productReference = BA4321F624CF420700D6B7D0 /* GameOfLifeTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + BA43220024CF420700D6B7D0 /* GameOfLifeUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = BA43221024CF420700D6B7D0 /* Build configuration list for PBXNativeTarget "GameOfLifeUITests" */; + buildPhases = ( + BA4321FD24CF420700D6B7D0 /* Sources */, + BA4321FE24CF420700D6B7D0 /* Frameworks */, + BA4321FF24CF420700D6B7D0 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + BA43220324CF420700D6B7D0 /* PBXTargetDependency */, + ); + name = GameOfLifeUITests; + productName = GameOfLifeUITests; + productReference = BA43220124CF420700D6B7D0 /* GameOfLifeUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + BA4321D524CF420600D6B7D0 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1150; + LastUpgradeCheck = 1150; + ORGANIZATIONNAME = "Bharat Kumar"; + TargetAttributes = { + BA4321DC24CF420600D6B7D0 = { + CreatedOnToolsVersion = 11.5; + }; + BA4321F524CF420700D6B7D0 = { + CreatedOnToolsVersion = 11.5; + TestTargetID = BA4321DC24CF420600D6B7D0; + }; + BA43220024CF420700D6B7D0 = { + CreatedOnToolsVersion = 11.5; + TestTargetID = BA4321DC24CF420600D6B7D0; + }; + }; + }; + buildConfigurationList = BA4321D824CF420600D6B7D0 /* Build configuration list for PBXProject "GameOfLife" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = BA4321D424CF420600D6B7D0; + productRefGroup = BA4321DE24CF420600D6B7D0 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + BA4321DC24CF420600D6B7D0 /* GameOfLife */, + BA4321F524CF420700D6B7D0 /* GameOfLifeTests */, + BA43220024CF420700D6B7D0 /* GameOfLifeUITests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + BA4321DB24CF420600D6B7D0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + BA4321F024CF420700D6B7D0 /* LaunchScreen.storyboard in Resources */, + BA4321ED24CF420700D6B7D0 /* Assets.xcassets in Resources */, + BA45D3DD24D373FC00648F91 /* Sky.mp3 in Resources */, + BA4321E824CF420600D6B7D0 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + BA4321F424CF420700D6B7D0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + BA4321FF24CF420700D6B7D0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + BA4321D924CF420600D6B7D0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + BA4321E524CF420600D6B7D0 /* ViewController.swift in Sources */, + BA43221A24CF77A700D6B7D0 /* CellGridView.swift in Sources */, + BA54CBE524D0CF9A008FE187 /* GameRulesViewController.swift in Sources */, + BA54CBE324D086A9008FE187 /* GridWorld.swift in Sources */, + BA4321E124CF420600D6B7D0 /* AppDelegate.swift in Sources */, + BA4321E324CF420600D6B7D0 /* SceneDelegate.swift in Sources */, + BA43221C24CF77FB00D6B7D0 /* Cell.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + BA4321F224CF420700D6B7D0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + BA4321FB24CF420700D6B7D0 /* GameOfLifeTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + BA4321FD24CF420700D6B7D0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + BA43220624CF420700D6B7D0 /* GameOfLifeUITests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + BA4321F824CF420700D6B7D0 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = BA4321DC24CF420600D6B7D0 /* GameOfLife */; + targetProxy = BA4321F724CF420700D6B7D0 /* PBXContainerItemProxy */; + }; + BA43220324CF420700D6B7D0 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = BA4321DC24CF420600D6B7D0 /* GameOfLife */; + targetProxy = BA43220224CF420700D6B7D0 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + BA4321E624CF420600D6B7D0 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + BA4321E724CF420600D6B7D0 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + BA4321EE24CF420700D6B7D0 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + BA4321EF24CF420700D6B7D0 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + BA43220824CF420700D6B7D0 /* 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; + }; + BA43220924CF420700D6B7D0 /* 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; + }; + BA43220B24CF420700D6B7D0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = MFBD923VWU; + INFOPLIST_FILE = GameOfLife/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = Bharat.GameOfLife; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + BA43220C24CF420700D6B7D0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = MFBD923VWU; + INFOPLIST_FILE = GameOfLife/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = Bharat.GameOfLife; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + BA43220E24CF420700D6B7D0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = MFBD923VWU; + INFOPLIST_FILE = GameOfLifeTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.5; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = Bharat.GameOfLifeTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GameOfLife.app/GameOfLife"; + }; + name = Debug; + }; + BA43220F24CF420700D6B7D0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = MFBD923VWU; + INFOPLIST_FILE = GameOfLifeTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.5; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = Bharat.GameOfLifeTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GameOfLife.app/GameOfLife"; + }; + name = Release; + }; + BA43221124CF420700D6B7D0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = MFBD923VWU; + INFOPLIST_FILE = GameOfLifeUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = Bharat.GameOfLifeUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = GameOfLife; + }; + name = Debug; + }; + BA43221224CF420700D6B7D0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = MFBD923VWU; + INFOPLIST_FILE = GameOfLifeUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = Bharat.GameOfLifeUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = GameOfLife; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + BA4321D824CF420600D6B7D0 /* Build configuration list for PBXProject "GameOfLife" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BA43220824CF420700D6B7D0 /* Debug */, + BA43220924CF420700D6B7D0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + BA43220A24CF420700D6B7D0 /* Build configuration list for PBXNativeTarget "GameOfLife" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BA43220B24CF420700D6B7D0 /* Debug */, + BA43220C24CF420700D6B7D0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + BA43220D24CF420700D6B7D0 /* Build configuration list for PBXNativeTarget "GameOfLifeTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BA43220E24CF420700D6B7D0 /* Debug */, + BA43220F24CF420700D6B7D0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + BA43221024CF420700D6B7D0 /* Build configuration list for PBXNativeTarget "GameOfLifeUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BA43221124CF420700D6B7D0 /* Debug */, + BA43221224CF420700D6B7D0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = BA4321D524CF420600D6B7D0 /* Project object */; +} diff --git a/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..672cfb935 --- /dev/null +++ b/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/xcuserdata/bharatdev.xcuserdatad/UserInterfaceState.xcuserstate b/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/xcuserdata/bharatdev.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 000000000..f2f8e8512 Binary files /dev/null and b/GameOfLife/GameOfLife.xcodeproj/project.xcworkspace/xcuserdata/bharatdev.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/GameOfLife/GameOfLife.xcodeproj/xcshareddata/xcschemes/GameOfLife.xcscheme b/GameOfLife/GameOfLife.xcodeproj/xcshareddata/xcschemes/GameOfLife.xcscheme new file mode 100644 index 000000000..fac992d8c --- /dev/null +++ b/GameOfLife/GameOfLife.xcodeproj/xcshareddata/xcschemes/GameOfLife.xcscheme @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GameOfLife/GameOfLife.xcodeproj/xcuserdata/bharatdev.xcuserdatad/xcschemes/xcschememanagement.plist b/GameOfLife/GameOfLife.xcodeproj/xcuserdata/bharatdev.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 000000000..aa2ff7927 --- /dev/null +++ b/GameOfLife/GameOfLife.xcodeproj/xcuserdata/bharatdev.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,32 @@ + + + + + SchemeUserState + + GameOfLife.xcscheme_^#shared#^_ + + orderHint + 0 + + + SuppressBuildableAutocreation + + BA4321DC24CF420600D6B7D0 + + primary + + + BA4321F524CF420700D6B7D0 + + primary + + + BA43220024CF420700D6B7D0 + + primary + + + + + diff --git a/GameOfLife/GameOfLife/AppDelegate.swift b/GameOfLife/GameOfLife/AppDelegate.swift new file mode 100644 index 000000000..7f3f6d6f4 --- /dev/null +++ b/GameOfLife/GameOfLife/AppDelegate.swift @@ -0,0 +1,82 @@ +// +// AppDelegate.swift +// GameOfLife +// +// Created by Bharat Kumar on 7/27/20. +// Copyright © 2020 Bharat Kumar. 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: "GameOfLife") + 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/GameOfLife/GameOfLife/Assets.xcassets/AppIcon.appiconset/Contents.json b/GameOfLife/GameOfLife/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..9221b9bb1 --- /dev/null +++ b/GameOfLife/GameOfLife/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/GameOfLife/GameOfLife/Assets.xcassets/Contents.json b/GameOfLife/GameOfLife/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/GameOfLife/GameOfLife/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/GameOfLife/GameOfLife/Base.lproj/LaunchScreen.storyboard b/GameOfLife/GameOfLife/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 000000000..865e9329f --- /dev/null +++ b/GameOfLife/GameOfLife/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GameOfLife/GameOfLife/Base.lproj/Main.storyboard b/GameOfLife/GameOfLife/Base.lproj/Main.storyboard new file mode 100644 index 000000000..06d357de0 --- /dev/null +++ b/GameOfLife/GameOfLife/Base.lproj/Main.storyboard @@ -0,0 +1,262 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1. Any live cell with fewer than two live neighbours dies, as if by underpopulation.
 +2. Any live cell with two or three live neighbours lives on to the next generation. +
3. Any live cell with more than three live neighbours dies, as if by overpopulation. +
4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GameOfLife/GameOfLife/CellGridView.swift b/GameOfLife/GameOfLife/CellGridView.swift new file mode 100644 index 000000000..dedf555ec --- /dev/null +++ b/GameOfLife/GameOfLife/CellGridView.swift @@ -0,0 +1,69 @@ +// +// CellGridView.swift +// GameOfLife +// +// Created by Bharat Kumar on 7/27/20. +// Copyright © 2020 Bharat Kumar. All rights reserved. +// + +import Foundation +import UIKit + +class CellGridView: UIView { + + var gridWorld = GridWorld(gridSize: 25) + private var cellSize: Int = 15 + private var timer: Timer? + var timeInterval = 0.25 + var timerRunning: Bool { + timer == nil ? false : true + } + + + public convenience init(gridSize: Int, cellSize: Int) { + let frame = CGRect(x: 0, y: 0, width: cellSize * gridSize, height: cellSize * gridSize) + self.init(frame: frame) + self.gridWorld = GridWorld(gridSize: gridSize) + self.cellSize = cellSize + } + + public required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + public override init(frame: CGRect) { + super.init(frame: frame) + } + + public func cancelTimer() { + timer?.invalidate() + timer = nil + } + + public func cellTapped(at index: Int) { + gridWorld.cellTapped(at: index) + setNeedsDisplay() + } + + @objc private func performGameTurn() { + self.gridWorld.performGameTurn() + self.setNeedsDisplay() + } + + public func startTimer() { + timer = Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(performGameTurn), userInfo: nil, repeats: true) + + } + + public func step() { + gridWorld.performGameTurn() + setNeedsDisplay() + } + + public func useExamplePattern(pattern: Patterns) { + gridWorld.clearGrid() + gridWorld.useExamplePattern(pattern: pattern) + setNeedsDisplay() + } + +} diff --git a/GameOfLife/GameOfLife/GameOfLife.xcdatamodeld/.xccurrentversion b/GameOfLife/GameOfLife/GameOfLife.xcdatamodeld/.xccurrentversion new file mode 100644 index 000000000..0c67376eb --- /dev/null +++ b/GameOfLife/GameOfLife/GameOfLife.xcdatamodeld/.xccurrentversion @@ -0,0 +1,5 @@ + + + + + diff --git a/GameOfLife/GameOfLife/GameOfLife.xcdatamodeld/GameOfLife.xcdatamodel/contents b/GameOfLife/GameOfLife/GameOfLife.xcdatamodeld/GameOfLife.xcdatamodel/contents new file mode 100644 index 000000000..50d2514e8 --- /dev/null +++ b/GameOfLife/GameOfLife/GameOfLife.xcdatamodeld/GameOfLife.xcdatamodel/contents @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/GameOfLife/GameOfLife/GameRulesViewController.swift b/GameOfLife/GameOfLife/GameRulesViewController.swift new file mode 100644 index 000000000..4c3624ca9 --- /dev/null +++ b/GameOfLife/GameOfLife/GameRulesViewController.swift @@ -0,0 +1,79 @@ +// +// GameRulesViewController.swift +// GameOfLife +// +// Created by Bharat Kumar on 7/28/20. +// Copyright © 2020 Bharat Kumar. All rights reserved. +// + +import UIKit + +class GameRulesViewController: UIViewController { + + var gridView : CellGridView? + var viewController: ViewController? + + @IBOutlet weak var speedOutlet: UISegmentedControl! + @IBOutlet weak var colorOutlet: UISegmentedControl! + override func viewDidLoad() { + super.viewDidLoad() + + switch(gridView?.timeInterval) { + case 0.50: + speedOutlet.selectedSegmentIndex = 1 + case 0.75: + speedOutlet.selectedSegmentIndex = 2 + case 1.00: + speedOutlet.selectedSegmentIndex = 3 + default: + speedOutlet.selectedSegmentIndex = 0 + } + + // Load current color + switch(viewController?.buttonColor) { + case UIColor.systemGreen: + colorOutlet.selectedSegmentIndex = 1 + case UIColor.systemYellow: + colorOutlet.selectedSegmentIndex = 2 + default: // UIColor.systemTeal + colorOutlet.selectedSegmentIndex = 0 + } + } + + @IBAction func speedSegmentedController(_ sender: UISegmentedControl) { + switch(sender.selectedSegmentIndex) { + case 1: + gridView?.timeInterval = 0.50 + case 2: + gridView?.timeInterval = 0.75 + case 3: + gridView?.timeInterval = 1.00 + default: + gridView?.timeInterval = 0.25 + } + } + + @IBAction func colorSegmentedController(_ sender: UISegmentedControl) { + switch(sender.selectedSegmentIndex) { + case 1: + viewController?.buttonColor = UIColor.systemGreen + case 2: + viewController?.buttonColor = UIColor.systemYellow + default: + viewController?.buttonColor = UIColor.systemTeal + } + } + @IBAction func okButton(_ sender: Any) { + dismiss(animated: true, completion: nil) + } + /* + // 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/GameOfLife/GameOfLife/Info.plist b/GameOfLife/GameOfLife/Info.plist new file mode 100644 index 000000000..2a3483c0d --- /dev/null +++ b/GameOfLife/GameOfLife/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/GameOfLife/GameOfLife/Model/Cell.swift b/GameOfLife/GameOfLife/Model/Cell.swift new file mode 100644 index 000000000..58c18f3e2 --- /dev/null +++ b/GameOfLife/GameOfLife/Model/Cell.swift @@ -0,0 +1,28 @@ +// +// Cell.swift +// GameOfLife +// +// Created by Bharat Kumar on 7/27/20. +// Copyright © 2020 Bharat Kumar. All rights reserved. +// + +import Foundation + +public enum State { + case dead + case alive + +} + +class Cell: NSObject { + + var x: Int + var y: Int + var state: State + + public init(x: Int, y: Int, state: State = .dead) { + self.x = x + self.y = y + self.state = state + } +} diff --git a/GameOfLife/GameOfLife/Model/GridWorld.swift b/GameOfLife/GameOfLife/Model/GridWorld.swift new file mode 100644 index 000000000..3f3acd2b0 --- /dev/null +++ b/GameOfLife/GameOfLife/Model/GridWorld.swift @@ -0,0 +1,354 @@ +// +// GridWorld.swift +// GameOfLife +// +// Created by Bharat Kumar on 7/28/20. +// Copyright © 2020 Bharat Kumar. All rights reserved. +// + +import Foundation +import UIKit +public enum Patterns { + case random + + // Still Lifes + case behive + + // Oscillators + case blinker + case toad + case beacon + case pulsar + case pentadecathlon + + // Spaceships + case glider +} + +protocol GameStatsDelegate { + func showGeneration() + func showPopulation() + func gridUpdated() +} + +class GridWorld: NSObject { + let size: Int + var cells: [Cell] = [] + var delegate: GameStatsDelegate? + + var generation = 0 + var population: Int { + cells.filter{ $0.state == .alive }.count + + } + + public init(gridSize: Int) { + self.size = gridSize + + // Create grid ttt + for y in 0.. Cell { + var absolutePosition: Int + // 3, 2 on 25 x 25 grid + absolutePosition = (y * size) + x + return cells[absolutePosition] + } + + func cellCoordinates(index: Int) -> (x: Int, y: Int) { + var y = 0 + var x = 0 + + y = index / size + x = index - (y * size) + + return (x, y) + } + + func cellTapped(at index: Int) { + if cells[index].state == .alive { + cells[index].state = .dead + } else { + cells[index].state = .alive + } + notifyDelegate() + } + + func performGameTurn() { + var index = 0 + var cellsToKill: [Cell] = [] + var cellsToBirth: [Cell] = [] + + for cell in cells { + var count = 0 + let coordinates = cellCoordinates(index: index) + + // West + if coordinates.x != 0 { + if cellAt(x: coordinates.x - 1, y: coordinates.y).state == .alive { + count = count + 1 + } + } + + // North West + if coordinates.x != 0 && coordinates.y != 0 { + if cellAt(x: coordinates.x - 1, y: coordinates.y - 1).state == .alive { + count = count + 1 + } + } + + // North + if coordinates.y != 0 { + if cellAt(x: coordinates.x, y: coordinates.y - 1).state == .alive { + count = count + 1 + } + } + + // North East + if coordinates.x < (size - 1) && coordinates.y != 0 { + if cellAt(x: coordinates.x + 1, y: coordinates.y - 1).state == .alive { + count = count + 1 + } + } + + // East + if coordinates.x < (size - 1) { + if cellAt(x: coordinates.x + 1, y: coordinates.y).state == .alive { + count = count + 1 + } + } + + // South East + if coordinates.x < (size - 1) && coordinates.y < (size - 1) { + if cellAt(x: coordinates.x + 1, y: coordinates.y + 1).state == .alive { + count = count + 1 + } + } + + // South + if coordinates.y < (size - 1) { + if cellAt(x: coordinates.x, y: coordinates.y + 1).state == .alive { + count = count + 1 + } + } + + // South West + if coordinates.x != 0 && coordinates.y < (size - 1) { + if cellAt(x: coordinates.x - 1, y: coordinates.y + 1).state == .alive { + count = count + 1 + } + } + + if cell.state == .alive { + if count < 2 || count > 3 { + cellsToKill.append(cell) + } + } else { // cell.state == .dead + if count == 3 { + cellsToBirth.append(cell) + } + } + index = index + 1 + } + + for cell in cellsToKill { + cell.state = .dead + } + + for cell in cellsToBirth { + cell.state = .alive + } + + generation += 1 + notifyDelegate() + } + + private func notifyDelegate() { + delegate?.showGeneration() + delegate?.showPopulation() + delegate?.gridUpdated() + } +} diff --git a/GameOfLife/GameOfLife/SceneDelegate.swift b/GameOfLife/GameOfLife/SceneDelegate.swift new file mode 100644 index 000000000..457e2990a --- /dev/null +++ b/GameOfLife/GameOfLife/SceneDelegate.swift @@ -0,0 +1,56 @@ +// +// SceneDelegate.swift +// GameOfLife +// +// Created by Bharat Kumar on 7/27/20. +// Copyright © 2020 Bharat Kumar. 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/GameOfLife/GameOfLife/Sky.mp3 b/GameOfLife/GameOfLife/Sky.mp3 new file mode 100644 index 000000000..96aa4023c Binary files /dev/null and b/GameOfLife/GameOfLife/Sky.mp3 differ diff --git a/GameOfLife/GameOfLife/ViewController.swift b/GameOfLife/GameOfLife/ViewController.swift new file mode 100644 index 000000000..5db9abcd3 --- /dev/null +++ b/GameOfLife/GameOfLife/ViewController.swift @@ -0,0 +1,189 @@ +// +// ViewController.swift +// GameOfLife +// +// Created by Bharat Kumar on 7/27/20. +// Copyright © 2020 Bharat Kumar. All rights reserved. +// + +import UIKit +import AVFoundation +class ViewController: UIViewController { + + @IBOutlet weak var generationLabel: UILabel! + @IBOutlet weak var populationLabel: UILabel! + @IBOutlet weak var gridView: CellGridView! + @IBOutlet weak var playButtonOutlet: UIButton! + + var audioPlayer = AVAudioPlayer() + var buttons: [UIButton] = [] + var buttonColor = UIColor.systemTeal { + didSet { + gridUpdated() + } + } + override func viewDidLoad() { + super.viewDidLoad() + setupButtons() + gridView.gridWorld.delegate = self + showGeneration() + showPopulation() + gridUpdated() + correctAndWrongAudio() + // Do any additional setup after loading the view. + } + @IBAction func playButtonTapped(_ sender: Any) { + + if gridView.timerRunning { + pauseGame() + audioPlayer.stop() + } else { + playButtonOutlet.isSelected = true + gridView.startTimer() + audioPlayer.play() + } + } + @IBAction func clearButtonTapped(_ sender: UIButton) { + pauseGame() + gridView.gridWorld.clearGrid() + } + + @IBAction func stepOver(_ sender: UIButton) { + gridView.step() + } + @IBAction func patternsButtonTapped(_ sender: UIButton) { + pauseGame() + + let alertController = UIAlertController(title: "Example Patterns", message: "Select a Game of Life pattern:", preferredStyle: .alert) + + alertController.addAction(UIAlertAction(title: "Random Pattern", style: .default) { _ in + self.gridView.useExamplePattern(pattern: .random) + }) + + alertController.addAction(UIAlertAction(title: "Behive", style: .default) { _ in + self.gridView.useExamplePattern(pattern: .behive) + }) + + alertController.addAction(UIAlertAction(title: "Blinker", style: .default) { _ in + self.gridView.useExamplePattern(pattern: .blinker) + }) + + alertController.addAction(UIAlertAction(title: "Toad", style: .default) { _ in + self.gridView.useExamplePattern(pattern: .toad) + }) + + alertController.addAction(UIAlertAction(title: "Beacon", style: .default) { _ in + self.gridView.useExamplePattern(pattern: .beacon) + }) + + alertController.addAction(UIAlertAction(title: "Pulsar", style: .default) { _ in + self.gridView.useExamplePattern(pattern: .pulsar) + }) + + alertController.addAction(UIAlertAction(title: "Pentadecathlon", style: .default) { _ in + self.gridView.useExamplePattern(pattern: .pentadecathlon) + }) + + alertController.addAction(UIAlertAction(title: "Glider", style: .default) { _ in + self.gridView.useExamplePattern(pattern: .glider) + }) + + alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil)) + + present(alertController, animated: true, completion: nil) + } + private func pauseGame() { + playButtonOutlet.isSelected = false + gridView.cancelTimer() + } + + @objc private func buttonTapped(_ sender: UIButton) { + print(sender.tag) + gridView.cellTapped(at: sender.tag) + } + private func setupButtons() { + var index = 0 + var topOffset = CGFloat(0) + var leadingOffset = CGFloat(0) + + for y in 0..= 375 { + leadingOffset = 0 + } + } + topOffset += 15 + } + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.identifier == "RulesSegue" { + guard let vc = segue.destination as? GameRulesViewController else { return } + vc.gridView = gridView + vc.viewController = self + } + } + +} + +extension ViewController: GameStatsDelegate { + func gridUpdated() { + var index = 0 + for cell in gridView.gridWorld.cells { + if cell.state == .alive { + buttons[index].backgroundColor = buttonColor + } else { + buttons[index].backgroundColor = .clear + } + index = index + 1 + } + } + + func showGeneration() { + generationLabel.text = "\(gridView.gridWorld.generation)" + } + + func showPopulation() { + populationLabel.text = "\(gridView.gridWorld.population)" + if gridView.gridWorld.population >= 70 { + populationLabel.textColor = UIColor.green + } else if gridView.gridWorld.population >= 50 { + populationLabel.textColor = UIColor.yellow + } else { + populationLabel.textColor = .red + } + } + + private func correctAndWrongAudio() { + let sound = Bundle.main.path(forResource: "Sky", ofType: "mp3") + do { + audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: sound!)) + + try AVAudioSession.sharedInstance().setCategory(.playback, options: .mixWithOthers) + + } catch { + print(error) + } + } +} diff --git a/GameOfLife/GameOfLifeTests/GameOfLifeTests.swift b/GameOfLife/GameOfLifeTests/GameOfLifeTests.swift new file mode 100644 index 000000000..2652fd4c8 --- /dev/null +++ b/GameOfLife/GameOfLifeTests/GameOfLifeTests.swift @@ -0,0 +1,34 @@ +// +// GameOfLifeTests.swift +// GameOfLifeTests +// +// Created by Bharat Kumar on 7/27/20. +// Copyright © 2020 Bharat Kumar. All rights reserved. +// + +import XCTest +@testable import GameOfLife + +class GameOfLifeTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/GameOfLife/GameOfLifeTests/Info.plist b/GameOfLife/GameOfLifeTests/Info.plist new file mode 100644 index 000000000..64d65ca49 --- /dev/null +++ b/GameOfLife/GameOfLifeTests/Info.plist @@ -0,0 +1,22 @@ + + + + + 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 + + diff --git a/GameOfLife/GameOfLifeUITests/GameOfLifeUITests.swift b/GameOfLife/GameOfLifeUITests/GameOfLifeUITests.swift new file mode 100644 index 000000000..87182917c --- /dev/null +++ b/GameOfLife/GameOfLifeUITests/GameOfLifeUITests.swift @@ -0,0 +1,43 @@ +// +// GameOfLifeUITests.swift +// GameOfLifeUITests +// +// Created by Bharat Kumar on 7/27/20. +// Copyright © 2020 Bharat Kumar. All rights reserved. +// + +import XCTest + +class GameOfLifeUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use recording to get started writing UI tests. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testLaunchPerformance() throws { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) { + XCUIApplication().launch() + } + } + } +} diff --git a/GameOfLife/GameOfLifeUITests/Info.plist b/GameOfLife/GameOfLifeUITests/Info.plist new file mode 100644 index 000000000..64d65ca49 --- /dev/null +++ b/GameOfLife/GameOfLifeUITests/Info.plist @@ -0,0 +1,22 @@ + + + + + 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 + +