From e273d9b9969252aecbe309e3a83c44dc1898e801 Mon Sep 17 00:00:00 2001 From: Sahel Jalal Date: Thu, 17 Dec 2020 01:09:04 -0800 Subject: [PATCH] Make basic collection view controller work --- .gitignore | 143 ++++++++++ Cellorama.xcodeproj/project.pbxproj | 244 +++++++++++++++++- .../xcschemes/xcschememanagement.plist | 2 +- .../contents.xcworkspacedata | 10 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + Cellorama/Base.lproj/Main.storyboard | 39 ++- Cellorama/Cells/CollectionCell.swift | 89 +++++++ Cellorama/Cells/Reusable.swift | 20 ++ Cellorama/Cells/TableCell.swift | 28 ++ .../Controllers/MainViewController.swift | 33 +++ Cellorama/Controllers/ViewController.swift | 35 +++ Cellorama/Models/CollectionDataSource.swift | 38 +++ Cellorama/Models/Item.swift | 54 ++++ Cellorama/Models/TableDataSource.swift | 17 ++ Cellorama/ViewController.swift | 19 -- Cellorama/Views/CollectionView.swift | 37 +++ Cellorama/Views/TableView.swift | 12 + Cellorama/Views/View.swift | 73 ++++++ Podfile | 20 ++ Podfile.lock | 16 ++ 20 files changed, 905 insertions(+), 32 deletions(-) create mode 100644 .gitignore create mode 100644 Cellorama.xcworkspace/contents.xcworkspacedata create mode 100644 Cellorama.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Cellorama/Cells/CollectionCell.swift create mode 100644 Cellorama/Cells/Reusable.swift create mode 100644 Cellorama/Cells/TableCell.swift create mode 100644 Cellorama/Controllers/MainViewController.swift create mode 100644 Cellorama/Controllers/ViewController.swift create mode 100644 Cellorama/Models/CollectionDataSource.swift create mode 100644 Cellorama/Models/Item.swift create mode 100644 Cellorama/Models/TableDataSource.swift delete mode 100644 Cellorama/ViewController.swift create mode 100644 Cellorama/Views/CollectionView.swift create mode 100644 Cellorama/Views/TableView.swift create mode 100644 Cellorama/Views/View.swift create mode 100644 Podfile create mode 100644 Podfile.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..08669cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,143 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/swift,xcode,cocoapods,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=swift,xcode,cocoapods,macos + +### CocoaPods ### +## CocoaPods GitIgnore Template + +# CocoaPods - Only use to conserve bandwidth / Save time on Pushing +# - Also handy if you have a large number of dependant pods +# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE +Pods/ + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# 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/ + +### Xcode ### +# Xcode +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + + + + +## Gcc Patch +/*.gcno + +### Xcode Patch ### +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcworkspace/contents.xcworkspacedata +**/xcshareddata/WorkspaceSettings.xcsettings + +# End of https://www.toptal.com/developers/gitignore/api/swift,xcode,cocoapods,macos diff --git a/Cellorama.xcodeproj/project.pbxproj b/Cellorama.xcodeproj/project.pbxproj index dd2c5cf..4a7b773 100644 --- a/Cellorama.xcodeproj/project.pbxproj +++ b/Cellorama.xcodeproj/project.pbxproj @@ -3,18 +3,31 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ + 97359F6A258B2F5000452290 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97359F69258B2F5000452290 /* ViewController.swift */; }; + 974FC0EB258ABB5A00513807 /* CollectionDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974FC0EA258ABB5A00513807 /* CollectionDataSource.swift */; }; + 974FC0F0258ABCB300513807 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974FC0EF258ABCB300513807 /* Item.swift */; }; + 974FC0F5258ABD4E00513807 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974FC0F4258ABD4E00513807 /* CollectionCell.swift */; }; + 974FC0FA258ABF8100513807 /* TableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974FC0F9258ABF8100513807 /* TableCell.swift */; }; + 974FC103258AC16200513807 /* TableDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974FC102258AC16200513807 /* TableDataSource.swift */; }; + 97820187258AD962005D73A1 /* Reusable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97820186258AD962005D73A1 /* Reusable.swift */; }; + 97C9F512258AB1B80031C862 /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97C9F511258AB1B80031C862 /* TableView.swift */; }; + 97C9F517258AB3DF0031C862 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97C9F516258AB3DF0031C862 /* View.swift */; }; 97EE80E1258AAF6500C6FE52 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97EE80E0258AAF6500C6FE52 /* AppDelegate.swift */; }; 97EE80E3258AAF6500C6FE52 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97EE80E2258AAF6500C6FE52 /* SceneDelegate.swift */; }; - 97EE80E5258AAF6500C6FE52 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97EE80E4258AAF6500C6FE52 /* ViewController.swift */; }; + 97EE80E5258AAF6500C6FE52 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97EE80E4258AAF6500C6FE52 /* MainViewController.swift */; }; 97EE80E8258AAF6500C6FE52 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97EE80E6258AAF6500C6FE52 /* Main.storyboard */; }; 97EE80EA258AAF6600C6FE52 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97EE80E9258AAF6600C6FE52 /* Assets.xcassets */; }; 97EE80ED258AAF6600C6FE52 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97EE80EB258AAF6600C6FE52 /* LaunchScreen.storyboard */; }; 97EE80F8258AAF6600C6FE52 /* CelloramaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97EE80F7258AAF6600C6FE52 /* CelloramaTests.swift */; }; 97EE8103258AAF6600C6FE52 /* CelloramaUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97EE8102258AAF6600C6FE52 /* CelloramaUITests.swift */; }; + 97EE8114258AB08100C6FE52 /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97EE8113258AB08100C6FE52 /* CollectionView.swift */; }; + AA370E4A537BB2086086091D /* Pods_Cellorama_CelloramaUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A3408D8BE018F337B64DB709 /* Pods_Cellorama_CelloramaUITests.framework */; }; + B998013F5C843F6D8228D389 /* Pods_CelloramaTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E00B8F10F5D044F824C278B /* Pods_CelloramaTests.framework */; }; + E237B5A854A64F9B3E67628E /* Pods_Cellorama.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93078C692283326CE98C5723 /* Pods_Cellorama.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -35,10 +48,24 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0E00B8F10F5D044F824C278B /* Pods_CelloramaTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CelloramaTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 3B20E5F5810D666BBE6BFE97 /* Pods-Cellorama-CelloramaUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Cellorama-CelloramaUITests.debug.xcconfig"; path = "Target Support Files/Pods-Cellorama-CelloramaUITests/Pods-Cellorama-CelloramaUITests.debug.xcconfig"; sourceTree = ""; }; + 421AD5DA7587B11E6058ED79 /* Pods-Cellorama.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Cellorama.debug.xcconfig"; path = "Target Support Files/Pods-Cellorama/Pods-Cellorama.debug.xcconfig"; sourceTree = ""; }; + 65B1CF9FC6B7384A6292E1C7 /* Pods-CelloramaTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CelloramaTests.release.xcconfig"; path = "Target Support Files/Pods-CelloramaTests/Pods-CelloramaTests.release.xcconfig"; sourceTree = ""; }; + 93078C692283326CE98C5723 /* Pods_Cellorama.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Cellorama.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 97359F69258B2F5000452290 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 974FC0EA258ABB5A00513807 /* CollectionDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionDataSource.swift; sourceTree = ""; }; + 974FC0EF258ABCB300513807 /* Item.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Item.swift; sourceTree = ""; }; + 974FC0F4258ABD4E00513807 /* CollectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionCell.swift; sourceTree = ""; }; + 974FC0F9258ABF8100513807 /* TableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableCell.swift; sourceTree = ""; }; + 974FC102258AC16200513807 /* TableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableDataSource.swift; sourceTree = ""; }; + 97820186258AD962005D73A1 /* Reusable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reusable.swift; sourceTree = ""; }; + 97C9F511258AB1B80031C862 /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = ""; }; + 97C9F516258AB3DF0031C862 /* View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = ""; }; 97EE80DD258AAF6500C6FE52 /* Cellorama.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Cellorama.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97EE80E0258AAF6500C6FE52 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 97EE80E2258AAF6500C6FE52 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - 97EE80E4258AAF6500C6FE52 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 97EE80E4258AAF6500C6FE52 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; 97EE80E7258AAF6500C6FE52 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 97EE80E9258AAF6600C6FE52 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97EE80EC258AAF6600C6FE52 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -49,6 +76,11 @@ 97EE80FE258AAF6600C6FE52 /* CelloramaUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CelloramaUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 97EE8102258AAF6600C6FE52 /* CelloramaUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CelloramaUITests.swift; sourceTree = ""; }; 97EE8104258AAF6600C6FE52 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 97EE8113258AB08100C6FE52 /* CollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionView.swift; sourceTree = ""; }; + A3408D8BE018F337B64DB709 /* Pods_Cellorama_CelloramaUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Cellorama_CelloramaUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + AD91C14416A890D894A593BF /* Pods-Cellorama.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Cellorama.release.xcconfig"; path = "Target Support Files/Pods-Cellorama/Pods-Cellorama.release.xcconfig"; sourceTree = ""; }; + E7ADEF6A2140FA64025B6879 /* Pods-CelloramaTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CelloramaTests.debug.xcconfig"; path = "Target Support Files/Pods-CelloramaTests/Pods-CelloramaTests.debug.xcconfig"; sourceTree = ""; }; + EB98EE256568F7DD00B5AEF2 /* Pods-Cellorama-CelloramaUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Cellorama-CelloramaUITests.release.xcconfig"; path = "Target Support Files/Pods-Cellorama-CelloramaUITests/Pods-Cellorama-CelloramaUITests.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -56,6 +88,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E237B5A854A64F9B3E67628E /* Pods_Cellorama.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -63,6 +96,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + B998013F5C843F6D8228D389 /* Pods_CelloramaTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -70,12 +104,69 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + AA370E4A537BB2086086091D /* Pods_Cellorama_CelloramaUITests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 13F96177AE3EB6825578B83C /* Frameworks */ = { + isa = PBXGroup; + children = ( + 93078C692283326CE98C5723 /* Pods_Cellorama.framework */, + A3408D8BE018F337B64DB709 /* Pods_Cellorama_CelloramaUITests.framework */, + 0E00B8F10F5D044F824C278B /* Pods_CelloramaTests.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 974FC0E9258ABB4400513807 /* Protocols */ = { + isa = PBXGroup; + children = ( + ); + path = Protocols; + sourceTree = ""; + }; + 974FC101258ABFC000513807 /* Models */ = { + isa = PBXGroup; + children = ( + 974FC0EA258ABB5A00513807 /* CollectionDataSource.swift */, + 974FC102258AC16200513807 /* TableDataSource.swift */, + 974FC0EF258ABCB300513807 /* Item.swift */, + ); + path = Models; + sourceTree = ""; + }; + 97C9F50E258AB1770031C862 /* Views */ = { + isa = PBXGroup; + children = ( + 97EE8113258AB08100C6FE52 /* CollectionView.swift */, + 97C9F511258AB1B80031C862 /* TableView.swift */, + 97C9F516258AB3DF0031C862 /* View.swift */, + ); + path = Views; + sourceTree = ""; + }; + 97C9F50F258AB17F0031C862 /* Cells */ = { + isa = PBXGroup; + children = ( + 974FC0F4258ABD4E00513807 /* CollectionCell.swift */, + 974FC0F9258ABF8100513807 /* TableCell.swift */, + 97820186258AD962005D73A1 /* Reusable.swift */, + ); + path = Cells; + sourceTree = ""; + }; + 97C9F510258AB1860031C862 /* Controllers */ = { + isa = PBXGroup; + children = ( + 97EE80E4258AAF6500C6FE52 /* MainViewController.swift */, + 97359F69258B2F5000452290 /* ViewController.swift */, + ); + path = Controllers; + sourceTree = ""; + }; 97EE80D4258AAF6400C6FE52 = { isa = PBXGroup; children = ( @@ -83,6 +174,8 @@ 97EE80F6258AAF6600C6FE52 /* CelloramaTests */, 97EE8101258AAF6600C6FE52 /* CelloramaUITests */, 97EE80DE258AAF6500C6FE52 /* Products */, + ED85F239C9806BB2EDEEF63A /* Pods */, + 13F96177AE3EB6825578B83C /* Frameworks */, ); sourceTree = ""; }; @@ -99,9 +192,13 @@ 97EE80DF258AAF6500C6FE52 /* Cellorama */ = { isa = PBXGroup; children = ( + 97C9F50F258AB17F0031C862 /* Cells */, + 97C9F510258AB1860031C862 /* Controllers */, + 974FC101258ABFC000513807 /* Models */, + 974FC0E9258ABB4400513807 /* Protocols */, + 97C9F50E258AB1770031C862 /* Views */, 97EE80E0258AAF6500C6FE52 /* AppDelegate.swift */, 97EE80E2258AAF6500C6FE52 /* SceneDelegate.swift */, - 97EE80E4258AAF6500C6FE52 /* ViewController.swift */, 97EE80E6258AAF6500C6FE52 /* Main.storyboard */, 97EE80E9258AAF6600C6FE52 /* Assets.xcassets */, 97EE80EB258AAF6600C6FE52 /* LaunchScreen.storyboard */, @@ -128,6 +225,19 @@ path = CelloramaUITests; sourceTree = ""; }; + ED85F239C9806BB2EDEEF63A /* Pods */ = { + isa = PBXGroup; + children = ( + 421AD5DA7587B11E6058ED79 /* Pods-Cellorama.debug.xcconfig */, + AD91C14416A890D894A593BF /* Pods-Cellorama.release.xcconfig */, + 3B20E5F5810D666BBE6BFE97 /* Pods-Cellorama-CelloramaUITests.debug.xcconfig */, + EB98EE256568F7DD00B5AEF2 /* Pods-Cellorama-CelloramaUITests.release.xcconfig */, + E7ADEF6A2140FA64025B6879 /* Pods-CelloramaTests.debug.xcconfig */, + 65B1CF9FC6B7384A6292E1C7 /* Pods-CelloramaTests.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -135,9 +245,11 @@ isa = PBXNativeTarget; buildConfigurationList = 97EE8107258AAF6600C6FE52 /* Build configuration list for PBXNativeTarget "Cellorama" */; buildPhases = ( + F70D26EFB07E4D76ED9550E7 /* [CP] Check Pods Manifest.lock */, 97EE80D9258AAF6400C6FE52 /* Sources */, 97EE80DA258AAF6400C6FE52 /* Frameworks */, 97EE80DB258AAF6400C6FE52 /* Resources */, + 28B56AA73F46B672DE22C9A7 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -152,6 +264,7 @@ isa = PBXNativeTarget; buildConfigurationList = 97EE810A258AAF6600C6FE52 /* Build configuration list for PBXNativeTarget "CelloramaTests" */; buildPhases = ( + 5A2EAEB0B37ACB3506B631A0 /* [CP] Check Pods Manifest.lock */, 97EE80EF258AAF6600C6FE52 /* Sources */, 97EE80F0258AAF6600C6FE52 /* Frameworks */, 97EE80F1258AAF6600C6FE52 /* Resources */, @@ -170,9 +283,11 @@ isa = PBXNativeTarget; buildConfigurationList = 97EE810D258AAF6600C6FE52 /* Build configuration list for PBXNativeTarget "CelloramaUITests" */; buildPhases = ( + 45882D4CFF5F05C4B6A98E87 /* [CP] Check Pods Manifest.lock */, 97EE80FA258AAF6600C6FE52 /* Sources */, 97EE80FB258AAF6600C6FE52 /* Frameworks */, 97EE80FC258AAF6600C6FE52 /* Resources */, + C84E0AEB6A04C48ACA2CB2F9 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -253,13 +368,126 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 28B56AA73F46B672DE22C9A7 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Cellorama/Pods-Cellorama-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Cellorama/Pods-Cellorama-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Cellorama/Pods-Cellorama-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 45882D4CFF5F05C4B6A98E87 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Cellorama-CelloramaUITests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 5A2EAEB0B37ACB3506B631A0 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-CelloramaTests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + C84E0AEB6A04C48ACA2CB2F9 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Cellorama-CelloramaUITests/Pods-Cellorama-CelloramaUITests-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Cellorama-CelloramaUITests/Pods-Cellorama-CelloramaUITests-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Cellorama-CelloramaUITests/Pods-Cellorama-CelloramaUITests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + F70D26EFB07E4D76ED9550E7 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Cellorama-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 97EE80D9258AAF6400C6FE52 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 97EE80E5258AAF6500C6FE52 /* ViewController.swift in Sources */, + 97820187258AD962005D73A1 /* Reusable.swift in Sources */, + 974FC0FA258ABF8100513807 /* TableCell.swift in Sources */, + 974FC0EB258ABB5A00513807 /* CollectionDataSource.swift in Sources */, + 97EE80E5258AAF6500C6FE52 /* MainViewController.swift in Sources */, + 97C9F512258AB1B80031C862 /* TableView.swift in Sources */, + 97C9F517258AB3DF0031C862 /* View.swift in Sources */, + 974FC0F0258ABCB300513807 /* Item.swift in Sources */, + 974FC0F5258ABD4E00513807 /* CollectionCell.swift in Sources */, + 97359F6A258B2F5000452290 /* ViewController.swift in Sources */, 97EE80E1258AAF6500C6FE52 /* AppDelegate.swift in Sources */, + 97EE8114258AB08100C6FE52 /* CollectionView.swift in Sources */, + 974FC103258AC16200513807 /* TableDataSource.swift in Sources */, 97EE80E3258AAF6500C6FE52 /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -433,6 +661,7 @@ }; 97EE8108258AAF6600C6FE52 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 421AD5DA7587B11E6058ED79 /* Pods-Cellorama.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; @@ -452,6 +681,7 @@ }; 97EE8109258AAF6600C6FE52 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = AD91C14416A890D894A593BF /* Pods-Cellorama.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; @@ -471,6 +701,7 @@ }; 97EE810B258AAF6600C6FE52 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = E7ADEF6A2140FA64025B6879 /* Pods-CelloramaTests.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; @@ -493,6 +724,7 @@ }; 97EE810C258AAF6600C6FE52 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 65B1CF9FC6B7384A6292E1C7 /* Pods-CelloramaTests.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; @@ -515,6 +747,7 @@ }; 97EE810E258AAF6600C6FE52 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 3B20E5F5810D666BBE6BFE97 /* Pods-Cellorama-CelloramaUITests.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; @@ -535,6 +768,7 @@ }; 97EE810F258AAF6600C6FE52 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = EB98EE256568F7DD00B5AEF2 /* Pods-Cellorama-CelloramaUITests.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; diff --git a/Cellorama.xcodeproj/xcuserdata/saheljalal.xcuserdatad/xcschemes/xcschememanagement.plist b/Cellorama.xcodeproj/xcuserdata/saheljalal.xcuserdatad/xcschemes/xcschememanagement.plist index 8ab00a4..f8e817f 100644 --- a/Cellorama.xcodeproj/xcuserdata/saheljalal.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Cellorama.xcodeproj/xcuserdata/saheljalal.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ Cellorama.xcscheme_^#shared#^_ orderHint - 0 + 4 diff --git a/Cellorama.xcworkspace/contents.xcworkspacedata b/Cellorama.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..221da31 --- /dev/null +++ b/Cellorama.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/Cellorama.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Cellorama.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Cellorama.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Cellorama/Base.lproj/Main.storyboard b/Cellorama/Base.lproj/Main.storyboard index 25a7638..cbfb86a 100644 --- a/Cellorama/Base.lproj/Main.storyboard +++ b/Cellorama/Base.lproj/Main.storyboard @@ -1,24 +1,49 @@ - + + - + + - + - + + - + - + + - + + + + + + + + + + + + + + + + + + + + + + diff --git a/Cellorama/Cells/CollectionCell.swift b/Cellorama/Cells/CollectionCell.swift new file mode 100644 index 0000000..e7bcf90 --- /dev/null +++ b/Cellorama/Cells/CollectionCell.swift @@ -0,0 +1,89 @@ +// +// CollectionCell.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit + +class CollectionCell: UICollectionViewCell, Reusable { + + weak var containerViewController: UIViewController? + var childViewController: UIViewController? + + override init(frame: CGRect) { + super.init(frame: frame) + + layer.cornerRadius = 10 + layer.masksToBounds = false + layer.shadowColor = UIColor.black.cgColor + layer.shadowOpacity = 0.2 + layer.shadowOffset = .zero + layer.shadowRadius = 5 + contentView.layer.cornerRadius = 10 + contentView.layer.masksToBounds = true + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + + layer.shadowPath = UIBezierPath(rect: bounds).cgPath + } + + func configure(item: Item) { + configure(container: item.asContainer) + configure(element: item.asElement) + } + + func configure(container: Container?) { + guard let container = container, + let containerViewController = containerViewController else { return } + + let source = CollectionDataSource(container: container, containerViewController: containerViewController) + let view = CollectionView(source: source) + + configure(view: view) + } + + func configure(element: Element?) { + guard let element = element else { return } + + let vc = ViewController(element: element) + configure(viewController: vc) + } + + func configure(view: UIView) { + contentView.addSubview(view) + view.snp.makeConstraints { make in + make.edges.equalToSuperview().priority(999) + } + } + + func configure(viewController: UIViewController) { + guard let containerViewController = containerViewController else { return } + + containerViewController.addChild(viewController) + contentView.addSubview(viewController.view) + viewController.view.snp.makeConstraints { make in + make.edges.equalToSuperview().priority(999) + } + viewController.didMove(toParent: containerViewController) + childViewController = viewController + } + + override func prepareForReuse() { + super.prepareForReuse() + + guard let childViewController = childViewController else { return } + + childViewController.willMove(toParent: nil) + childViewController.view.removeFromSuperview() + childViewController.removeFromParent() + } + +} diff --git a/Cellorama/Cells/Reusable.swift b/Cellorama/Cells/Reusable.swift new file mode 100644 index 0000000..a848eda --- /dev/null +++ b/Cellorama/Cells/Reusable.swift @@ -0,0 +1,20 @@ +// +// Reusable.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import Foundation + +protocol Reusable { + + static var reuseIdentifier: String { get } + +} + +extension Reusable { + + static var reuseIdentifier: String { String(describing: type(of: self)) } + +} diff --git a/Cellorama/Cells/TableCell.swift b/Cellorama/Cells/TableCell.swift new file mode 100644 index 0000000..4abe067 --- /dev/null +++ b/Cellorama/Cells/TableCell.swift @@ -0,0 +1,28 @@ +// +// TableCell.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit + +class TableCell: UITableViewCell, Reusable { + + enum Kind { + case container + case element + } + + var kind: Kind + + init(kind: Kind) { + self.kind = kind + super.init(style: .default, reuseIdentifier: TableCell.reuseIdentifier) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} diff --git a/Cellorama/Controllers/MainViewController.swift b/Cellorama/Controllers/MainViewController.swift new file mode 100644 index 0000000..19a888a --- /dev/null +++ b/Cellorama/Controllers/MainViewController.swift @@ -0,0 +1,33 @@ +// +// MainViewController.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit +import SnapKit + +class MainViewController: UIViewController { + + lazy var collectionView: CollectionView = { + var items: [Item] = [] + for _ in 1...100 { items.append(Element()) } + let container = Container(items: items) + let source = CollectionDataSource(container: container, containerViewController: self) + let view = CollectionView(source: source) + return view + }() + + override func viewDidLoad() { + super.viewDidLoad() + + title = "Cellorama" + + view.addSubview(collectionView) + collectionView.snp.makeConstraints { make in + make.edges.equalToSuperview() + } + } + +} diff --git a/Cellorama/Controllers/ViewController.swift b/Cellorama/Controllers/ViewController.swift new file mode 100644 index 0000000..337cdbf --- /dev/null +++ b/Cellorama/Controllers/ViewController.swift @@ -0,0 +1,35 @@ +// +// ViewController.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit +import SnapKit + +class ViewController: UIViewController { + + let element: Element + + init(element: Element) { + self.element = element + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + super.viewDidLoad() + + let view = View(element: element) + view.size = element.size + self.view.addSubview(view) + view.snp.makeConstraints { make in + make.edges.equalToSuperview() + } + } + +} diff --git a/Cellorama/Models/CollectionDataSource.swift b/Cellorama/Models/CollectionDataSource.swift new file mode 100644 index 0000000..e6c74c4 --- /dev/null +++ b/Cellorama/Models/CollectionDataSource.swift @@ -0,0 +1,38 @@ +// +// CollectionDataSource.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit + +final class CollectionDataSource: NSObject, UICollectionViewDataSource, UICollectionViewDelegate { + + var container: Container + var items: [Item] { container.items } + var numberOfItems: Int { items.count } + weak var containerViewController: UIViewController? + + init(container: Container, containerViewController: UIViewController) { + self.container = container + self.containerViewController = containerViewController + super.init() + } + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + numberOfItems + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard numberOfItems > indexPath.row else { return UICollectionViewCell() } + + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CollectionCell.reuseIdentifier, for: indexPath) as? CollectionCell else { return UICollectionViewCell() } + + cell.containerViewController = containerViewController + cell.configure(item: items[indexPath.row]) + + return cell + } + +} diff --git a/Cellorama/Models/Item.swift b/Cellorama/Models/Item.swift new file mode 100644 index 0000000..bdc23b8 --- /dev/null +++ b/Cellorama/Models/Item.swift @@ -0,0 +1,54 @@ +// +// Item.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit + +enum ItemKind { + + case container + case element + +} + +protocol Item { + + var kind: ItemKind { get } + var asContainer: Container? { get } + var asElement: Element? { get } + +} + +extension Item { + + var asContainer: Container? { self as? Container } + var asElement: Element? { self as? Element } + +} + +struct Container: Item { + + var kind: ItemKind = .container + var items: [Item] = [] + +} + +struct Element: Item { + + var kind: ItemKind = .element + var data: String = randomEmoji() + var size: View.Size = .random + var color: UIColor = randomColor() + +} + +func randomEmoji() -> String { + ["👊", "🤲", "🙌", "👏", "🤝", "👍", "👎", "✊", "🤛", "🤞", "✌️", "🤟", "👌", "🤏", "☝️", "🖖", "🤙"].randomElement()! +} + +func randomColor() -> UIColor { + [.blue, .black, .red, .green, .yellow, .brown, .cyan, .darkGray, .gray, .lightGray, .magenta, .orange, .purple, .white].randomElement()! +} diff --git a/Cellorama/Models/TableDataSource.swift b/Cellorama/Models/TableDataSource.swift new file mode 100644 index 0000000..4ae3f69 --- /dev/null +++ b/Cellorama/Models/TableDataSource.swift @@ -0,0 +1,17 @@ +// +// TableDataSource.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit + +struct TableDataSource { + + var items: [Item] = [] + var numberOfItems: Int { items.count } + + func configureCell(_ cell: TableCell, for item: Item) {} + +} diff --git a/Cellorama/ViewController.swift b/Cellorama/ViewController.swift deleted file mode 100644 index 77985b6..0000000 --- a/Cellorama/ViewController.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// ViewController.swift -// Cellorama -// -// Created by Sahel Jalal on 12/16/20. -// - -import UIKit - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - -} - diff --git a/Cellorama/Views/CollectionView.swift b/Cellorama/Views/CollectionView.swift new file mode 100644 index 0000000..6585fb3 --- /dev/null +++ b/Cellorama/Views/CollectionView.swift @@ -0,0 +1,37 @@ +// +// CollectionView.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit + +class CollectionView: UICollectionView { + + let layout: UICollectionViewFlowLayout = { + let layout = UICollectionViewFlowLayout() + layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize + layout.minimumInteritemSpacing = 10.0 + layout.sectionInset = UIEdgeInsets(top: 8.0, left: 8.0, bottom: 8.0, right: 8.0) + return layout + }() + + let source: CollectionDataSource + + init(source: CollectionDataSource) { + self.source = source + super.init(frame: .zero, collectionViewLayout: layout) + + dataSource = source + delegate = source + backgroundColor = .white + + register(CollectionCell.self, forCellWithReuseIdentifier: CollectionCell.reuseIdentifier) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} diff --git a/Cellorama/Views/TableView.swift b/Cellorama/Views/TableView.swift new file mode 100644 index 0000000..54ff76e --- /dev/null +++ b/Cellorama/Views/TableView.swift @@ -0,0 +1,12 @@ +// +// TableView.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit + +class TableView: UITableView { + +} diff --git a/Cellorama/Views/View.swift b/Cellorama/Views/View.swift new file mode 100644 index 0000000..71af807 --- /dev/null +++ b/Cellorama/Views/View.swift @@ -0,0 +1,73 @@ +// +// View.swift +// Cellorama +// +// Created by Sahel Jalal on 12/16/20. +// + +import UIKit + +class View: UIView { + + enum Size: CaseIterable { + case small + case medium + case large +// case dynamic + + static var random: Size { Size.allCases.randomElement()! } + + func configure(_ view: View) { + switch self { + case .small: + view.snp.remakeConstraints { make in + make.height.width.equalTo(60.0) + } + case .medium: + view.snp.remakeConstraints { make in + make.height.equalTo(60.0) + make.width.equalTo(100.0) + } + case .large: + view.snp.remakeConstraints { make in + make.height.equalTo(100.0) + make.width.equalTo(160.0) + } +// case .dynamic: return + } + } + } + + var size: Size = .small { + didSet { size.configure(self) } + } + + lazy var label: UILabel = { + let view = UILabel() + view.font = UIFont.preferredFont(forTextStyle: .headline) + view.numberOfLines = 2 + view.textColor = backgroundColor == .white ? .black : .white + view.textAlignment = .center + return view + }() + + init(element: Element) { + super.init(frame: .zero) + + backgroundColor = element.color + size = element.size + + addSubview(label) + label.snp.makeConstraints { make in + make.center.equalToSuperview() + } + label.text = element.data + + size.configure(self) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} diff --git a/Podfile b/Podfile new file mode 100644 index 0000000..b77907b --- /dev/null +++ b/Podfile @@ -0,0 +1,20 @@ +# Uncomment the next line to define a global platform for your project +# platform :ios, '9.0' + +target 'Cellorama' do + # Comment the next line if you don't want to use dynamic frameworks + use_frameworks! + + # Pods for Cellorama + pod 'SnapKit' + + target 'CelloramaTests' do + inherit! :search_paths + # Pods for testing + end + + target 'CelloramaUITests' do + # Pods for testing + end + +end diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 0000000..be46d88 --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,16 @@ +PODS: + - SnapKit (5.0.1) + +DEPENDENCIES: + - SnapKit + +SPEC REPOS: + trunk: + - SnapKit + +SPEC CHECKSUMS: + SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb + +PODFILE CHECKSUM: 65fecd9fa9addd289acb8b013d71d52c861d879e + +COCOAPODS: 1.9.1