├── .gitignore ├── .travis.yml ├── EnumList.podspec ├── LICENSE ├── Project ├── EnumListProject.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── EnumListProject.xcscheme ├── EnumListProject.xcworkspace │ └── contents.xcworkspacedata ├── EnumListProject │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift ├── EnumListProjectTests │ ├── EnumListDecodableTests.swift │ ├── EnumListEncodableTests.swift │ ├── EnumListTests.swift │ ├── EnumListUnboxTests.swift │ └── Info.plist ├── Podfile ├── Podfile.lock └── fastlane │ ├── Fastfile │ └── README.md ├── README.md └── Sources ├── APIConvenience.swift ├── EnumListRaw.swift ├── EnumListRawDecodable.swift ├── EnumListRawEncodable.swift ├── EnumValues.swift ├── EnumValuesExtensions.swift └── Unbox └── EnumList+Unbox.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | *.hmap 19 | *.ipa 20 | 21 | # Bundler 22 | vendor 23 | 24 | # CocoaPods 25 | Pods/ 26 | 27 | #fastlane 28 | output/ 29 | fastlane/screenshots/ 30 | 31 | # Fastlane temporary profiling data 32 | /fastlane/report.xml 33 | # Deliver temporary error output 34 | /fastlane/Error*.png 35 | # Deliver temporary preview output 36 | /fastlane/Preview.html 37 | # Snapshot generated screenshots 38 | /fastlane/screenshots/*/*-portrait.png 39 | /fastlane/screenshots/*/*-landscape.png 40 | /fastlane/screenshots/screenshots.html 41 | # Frameit generated screenshots 42 | /fastlane/screenshots/*/*-portrait_framed.png 43 | /fastlane/screenshots/*/*-landscape_framed.png 44 | 45 | *.orig 46 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode9 3 | xcode_project: Project/EnumListProject.xcodeworkspace 4 | xcode_scheme: EnumListProject 5 | 6 | 7 | 8 | env: 9 | - LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8 10 | before_install: 11 | - gem install cocoapods 12 | - gem install fastlane 13 | - gem install xcov 14 | - gem install coveralls 15 | 16 | script: 17 | - cd Project 18 | - fastlane test 19 | -------------------------------------------------------------------------------- /EnumList.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | spec.name = 'EnumList' 3 | spec.version = '0.2.0' 4 | spec.license = { :type => 'MIT' } 5 | spec.homepage = 'https://github.com/polac24/EnumList' 6 | spec.authors = { 'Bartosz Polaczyk' => 'polac24@gmail.com' } 7 | spec.summary = 'List all cases from enum' 8 | spec.source = { :git => 'https://github.com/polac24/EnumList.git', :tag => 'v0.2.0' } 9 | spec.platform = :ios 10 | spec.ios.deployment_target = '9.0' 11 | spec.module_name = 'EnumList' 12 | 13 | 14 | spec.subspec 'Core' do |unbox| 15 | unbox.source_files = 'Sources/*.swift' 16 | unbox.dependency 'Unbox', '~> 2.5.0' 17 | end 18 | 19 | spec.subspec 'Unbox' do |unbox| 20 | unbox.source_files = 'Sources/Unbox/*.swift' 21 | unbox.dependency 'Unbox', '~> 2.5.0' 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 polac24 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Project/EnumListProject.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 10005CC81F3F00F100DFB92D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10005CC71F3F00F100DFB92D /* AppDelegate.swift */; }; 11 | 10005CCA1F3F00F100DFB92D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10005CC91F3F00F100DFB92D /* ViewController.swift */; }; 12 | 10005CCD1F3F00F200DFB92D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 10005CCB1F3F00F200DFB92D /* Main.storyboard */; }; 13 | 10005CCF1F3F00F200DFB92D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 10005CCE1F3F00F200DFB92D /* Assets.xcassets */; }; 14 | 10005CD21F3F00F200DFB92D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 10005CD01F3F00F200DFB92D /* LaunchScreen.storyboard */; }; 15 | 10005CDD1F3F00F200DFB92D /* EnumListTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10005CDC1F3F00F200DFB92D /* EnumListTests.swift */; }; 16 | 1056D5E21F3F17580084D044 /* EnumListUnboxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1056D5E11F3F17580084D044 /* EnumListUnboxTests.swift */; }; 17 | 107498861F52E3D0004C5619 /* EnumListDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 107498851F52E3D0004C5619 /* EnumListDecodableTests.swift */; }; 18 | 1092413D1F53037400076DCA /* EnumListEncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1092413C1F53037400076DCA /* EnumListEncodableTests.swift */; }; 19 | 564544D0824CB27F51A92F0B /* Pods_EnumListProject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DFBB7BF08ECA23D7692638A9 /* Pods_EnumListProject.framework */; }; 20 | 7298351F563726AE0CE1B271 /* Pods_EnumListProjectTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 031C7AF19439B07D965E34B5 /* Pods_EnumListProjectTests.framework */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 10005CD91F3F00F200DFB92D /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 10005CBC1F3F00F100DFB92D /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 10005CC31F3F00F100DFB92D; 29 | remoteInfo = EnumListProject; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 031C7AF19439B07D965E34B5 /* Pods_EnumListProjectTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_EnumListProjectTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 10005CC41F3F00F100DFB92D /* EnumListProject.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EnumListProject.app; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | 10005CC71F3F00F100DFB92D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 37 | 10005CC91F3F00F100DFB92D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 38 | 10005CCC1F3F00F200DFB92D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | 10005CCE1F3F00F200DFB92D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | 10005CD11F3F00F200DFB92D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 41 | 10005CD31F3F00F200DFB92D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | 10005CD81F3F00F200DFB92D /* EnumListProjectTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EnumListProjectTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 10005CDC1F3F00F200DFB92D /* EnumListTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumListTests.swift; sourceTree = ""; }; 44 | 10005CDE1F3F00F200DFB92D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 1056D5E11F3F17580084D044 /* EnumListUnboxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumListUnboxTests.swift; sourceTree = ""; }; 46 | 1056D5E41F3F23AC0084D044 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 47 | 1056D5E81F3F413F0084D044 /* .travis.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = .travis.yml; path = ../.travis.yml; sourceTree = ""; }; 48 | 107498851F52E3D0004C5619 /* EnumListDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumListDecodableTests.swift; sourceTree = ""; }; 49 | 1092413C1F53037400076DCA /* EnumListEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumListEncodableTests.swift; sourceTree = ""; }; 50 | 14471477568D8E102EA85FC2 /* Pods-EnumListProject.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnumListProject.release.xcconfig"; path = "Pods/Target Support Files/Pods-EnumListProject/Pods-EnumListProject.release.xcconfig"; sourceTree = ""; }; 51 | 1D5F875EA599999652412E30 /* Pods-EnumListProjectTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnumListProjectTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-EnumListProjectTests/Pods-EnumListProjectTests.release.xcconfig"; sourceTree = ""; }; 52 | 5C2076FE89539B210F45DF0E /* Pods-EnumListProject.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnumListProject.debug.xcconfig"; path = "Pods/Target Support Files/Pods-EnumListProject/Pods-EnumListProject.debug.xcconfig"; sourceTree = ""; }; 53 | 74B0A481CC3EB74BC1D9C0AB /* Pods-EnumListProjectTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnumListProjectTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-EnumListProjectTests/Pods-EnumListProjectTests.debug.xcconfig"; sourceTree = ""; }; 54 | DFBB7BF08ECA23D7692638A9 /* Pods_EnumListProject.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_EnumListProject.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 10005CC11F3F00F100DFB92D /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | 564544D0824CB27F51A92F0B /* Pods_EnumListProject.framework in Frameworks */, 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | 10005CD51F3F00F200DFB92D /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | 7298351F563726AE0CE1B271 /* Pods_EnumListProjectTests.framework in Frameworks */, 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | /* End PBXFrameworksBuildPhase section */ 75 | 76 | /* Begin PBXGroup section */ 77 | 10005CBB1F3F00F100DFB92D = { 78 | isa = PBXGroup; 79 | children = ( 80 | 10005CC61F3F00F100DFB92D /* EnumListProject */, 81 | 10005CDB1F3F00F200DFB92D /* EnumListProjectTests */, 82 | 10005CC51F3F00F100DFB92D /* Products */, 83 | 447831527550AE73F78FB92F /* Pods */, 84 | F19219A9E69DF42705C59115 /* Frameworks */, 85 | 1056D5E31F3F23910084D044 /* RepoDocs */, 86 | ); 87 | sourceTree = ""; 88 | }; 89 | 10005CC51F3F00F100DFB92D /* Products */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 10005CC41F3F00F100DFB92D /* EnumListProject.app */, 93 | 10005CD81F3F00F200DFB92D /* EnumListProjectTests.xctest */, 94 | ); 95 | name = Products; 96 | sourceTree = ""; 97 | }; 98 | 10005CC61F3F00F100DFB92D /* EnumListProject */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 10005CC71F3F00F100DFB92D /* AppDelegate.swift */, 102 | 10005CC91F3F00F100DFB92D /* ViewController.swift */, 103 | 10005CCB1F3F00F200DFB92D /* Main.storyboard */, 104 | 10005CCE1F3F00F200DFB92D /* Assets.xcassets */, 105 | 10005CD01F3F00F200DFB92D /* LaunchScreen.storyboard */, 106 | 10005CD31F3F00F200DFB92D /* Info.plist */, 107 | ); 108 | path = EnumListProject; 109 | sourceTree = ""; 110 | }; 111 | 10005CDB1F3F00F200DFB92D /* EnumListProjectTests */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | 10005CDC1F3F00F200DFB92D /* EnumListTests.swift */, 115 | 10005CDE1F3F00F200DFB92D /* Info.plist */, 116 | 1056D5E11F3F17580084D044 /* EnumListUnboxTests.swift */, 117 | 107498851F52E3D0004C5619 /* EnumListDecodableTests.swift */, 118 | 1092413C1F53037400076DCA /* EnumListEncodableTests.swift */, 119 | ); 120 | path = EnumListProjectTests; 121 | sourceTree = ""; 122 | }; 123 | 1056D5E31F3F23910084D044 /* RepoDocs */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | 1056D5E41F3F23AC0084D044 /* README.md */, 127 | 1056D5E81F3F413F0084D044 /* .travis.yml */, 128 | ); 129 | name = RepoDocs; 130 | sourceTree = ""; 131 | }; 132 | 447831527550AE73F78FB92F /* Pods */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | 5C2076FE89539B210F45DF0E /* Pods-EnumListProject.debug.xcconfig */, 136 | 14471477568D8E102EA85FC2 /* Pods-EnumListProject.release.xcconfig */, 137 | 74B0A481CC3EB74BC1D9C0AB /* Pods-EnumListProjectTests.debug.xcconfig */, 138 | 1D5F875EA599999652412E30 /* Pods-EnumListProjectTests.release.xcconfig */, 139 | ); 140 | name = Pods; 141 | sourceTree = ""; 142 | }; 143 | F19219A9E69DF42705C59115 /* Frameworks */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | DFBB7BF08ECA23D7692638A9 /* Pods_EnumListProject.framework */, 147 | 031C7AF19439B07D965E34B5 /* Pods_EnumListProjectTests.framework */, 148 | ); 149 | name = Frameworks; 150 | sourceTree = ""; 151 | }; 152 | /* End PBXGroup section */ 153 | 154 | /* Begin PBXNativeTarget section */ 155 | 10005CC31F3F00F100DFB92D /* EnumListProject */ = { 156 | isa = PBXNativeTarget; 157 | buildConfigurationList = 10005CE11F3F00F200DFB92D /* Build configuration list for PBXNativeTarget "EnumListProject" */; 158 | buildPhases = ( 159 | D4395D8B24F7173161A0A6B8 /* [CP] Check Pods Manifest.lock */, 160 | 10005CC01F3F00F100DFB92D /* Sources */, 161 | 10005CC11F3F00F100DFB92D /* Frameworks */, 162 | 10005CC21F3F00F100DFB92D /* Resources */, 163 | 2B4FF9C41A7B866D78C0F761 /* [CP] Embed Pods Frameworks */, 164 | 3606EF977CFEAEFBEB37E483 /* [CP] Copy Pods Resources */, 165 | ); 166 | buildRules = ( 167 | ); 168 | dependencies = ( 169 | ); 170 | name = EnumListProject; 171 | productName = EnumListProject; 172 | productReference = 10005CC41F3F00F100DFB92D /* EnumListProject.app */; 173 | productType = "com.apple.product-type.application"; 174 | }; 175 | 10005CD71F3F00F200DFB92D /* EnumListProjectTests */ = { 176 | isa = PBXNativeTarget; 177 | buildConfigurationList = 10005CE41F3F00F200DFB92D /* Build configuration list for PBXNativeTarget "EnumListProjectTests" */; 178 | buildPhases = ( 179 | D1C4B1D346C51BAA62D305A9 /* [CP] Check Pods Manifest.lock */, 180 | 10005CD41F3F00F200DFB92D /* Sources */, 181 | 10005CD51F3F00F200DFB92D /* Frameworks */, 182 | 10005CD61F3F00F200DFB92D /* Resources */, 183 | FD756022EE3702EAE02C32ED /* [CP] Embed Pods Frameworks */, 184 | 335AB92A837B644FE6693F87 /* [CP] Copy Pods Resources */, 185 | ); 186 | buildRules = ( 187 | ); 188 | dependencies = ( 189 | 10005CDA1F3F00F200DFB92D /* PBXTargetDependency */, 190 | ); 191 | name = EnumListProjectTests; 192 | productName = EnumListProjectTests; 193 | productReference = 10005CD81F3F00F200DFB92D /* EnumListProjectTests.xctest */; 194 | productType = "com.apple.product-type.bundle.unit-test"; 195 | }; 196 | /* End PBXNativeTarget section */ 197 | 198 | /* Begin PBXProject section */ 199 | 10005CBC1F3F00F100DFB92D /* Project object */ = { 200 | isa = PBXProject; 201 | attributes = { 202 | LastSwiftUpdateCheck = 0830; 203 | LastUpgradeCheck = 0900; 204 | ORGANIZATIONNAME = "Bartosz Polaczyk"; 205 | TargetAttributes = { 206 | 10005CC31F3F00F100DFB92D = { 207 | CreatedOnToolsVersion = 8.3.2; 208 | LastSwiftMigration = 0900; 209 | ProvisioningStyle = Automatic; 210 | }; 211 | 10005CD71F3F00F200DFB92D = { 212 | CreatedOnToolsVersion = 8.3.2; 213 | LastSwiftMigration = 0900; 214 | ProvisioningStyle = Automatic; 215 | TestTargetID = 10005CC31F3F00F100DFB92D; 216 | }; 217 | }; 218 | }; 219 | buildConfigurationList = 10005CBF1F3F00F100DFB92D /* Build configuration list for PBXProject "EnumListProject" */; 220 | compatibilityVersion = "Xcode 3.2"; 221 | developmentRegion = English; 222 | hasScannedForEncodings = 0; 223 | knownRegions = ( 224 | en, 225 | Base, 226 | ); 227 | mainGroup = 10005CBB1F3F00F100DFB92D; 228 | productRefGroup = 10005CC51F3F00F100DFB92D /* Products */; 229 | projectDirPath = ""; 230 | projectRoot = ""; 231 | targets = ( 232 | 10005CC31F3F00F100DFB92D /* EnumListProject */, 233 | 10005CD71F3F00F200DFB92D /* EnumListProjectTests */, 234 | ); 235 | }; 236 | /* End PBXProject section */ 237 | 238 | /* Begin PBXResourcesBuildPhase section */ 239 | 10005CC21F3F00F100DFB92D /* Resources */ = { 240 | isa = PBXResourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | 10005CD21F3F00F200DFB92D /* LaunchScreen.storyboard in Resources */, 244 | 10005CCF1F3F00F200DFB92D /* Assets.xcassets in Resources */, 245 | 10005CCD1F3F00F200DFB92D /* Main.storyboard in Resources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | 10005CD61F3F00F200DFB92D /* Resources */ = { 250 | isa = PBXResourcesBuildPhase; 251 | buildActionMask = 2147483647; 252 | files = ( 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | /* End PBXResourcesBuildPhase section */ 257 | 258 | /* Begin PBXShellScriptBuildPhase section */ 259 | 2B4FF9C41A7B866D78C0F761 /* [CP] Embed Pods Frameworks */ = { 260 | isa = PBXShellScriptBuildPhase; 261 | buildActionMask = 2147483647; 262 | files = ( 263 | ); 264 | inputPaths = ( 265 | "${SRCROOT}/Pods/Target Support Files/Pods-EnumListProject/Pods-EnumListProject-frameworks.sh", 266 | "${BUILT_PRODUCTS_DIR}/EnumList/EnumList.framework", 267 | "${BUILT_PRODUCTS_DIR}/Unbox/Unbox.framework", 268 | ); 269 | name = "[CP] Embed Pods Frameworks"; 270 | outputPaths = ( 271 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/EnumList.framework", 272 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Unbox.framework", 273 | ); 274 | runOnlyForDeploymentPostprocessing = 0; 275 | shellPath = /bin/sh; 276 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-EnumListProject/Pods-EnumListProject-frameworks.sh\"\n"; 277 | showEnvVarsInLog = 0; 278 | }; 279 | 335AB92A837B644FE6693F87 /* [CP] Copy Pods Resources */ = { 280 | isa = PBXShellScriptBuildPhase; 281 | buildActionMask = 2147483647; 282 | files = ( 283 | ); 284 | inputPaths = ( 285 | ); 286 | name = "[CP] Copy Pods Resources"; 287 | outputPaths = ( 288 | ); 289 | runOnlyForDeploymentPostprocessing = 0; 290 | shellPath = /bin/sh; 291 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-EnumListProjectTests/Pods-EnumListProjectTests-resources.sh\"\n"; 292 | showEnvVarsInLog = 0; 293 | }; 294 | 3606EF977CFEAEFBEB37E483 /* [CP] Copy Pods Resources */ = { 295 | isa = PBXShellScriptBuildPhase; 296 | buildActionMask = 2147483647; 297 | files = ( 298 | ); 299 | inputPaths = ( 300 | ); 301 | name = "[CP] Copy Pods Resources"; 302 | outputPaths = ( 303 | ); 304 | runOnlyForDeploymentPostprocessing = 0; 305 | shellPath = /bin/sh; 306 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-EnumListProject/Pods-EnumListProject-resources.sh\"\n"; 307 | showEnvVarsInLog = 0; 308 | }; 309 | D1C4B1D346C51BAA62D305A9 /* [CP] Check Pods Manifest.lock */ = { 310 | isa = PBXShellScriptBuildPhase; 311 | buildActionMask = 2147483647; 312 | files = ( 313 | ); 314 | inputPaths = ( 315 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 316 | "${PODS_ROOT}/Manifest.lock", 317 | ); 318 | name = "[CP] Check Pods Manifest.lock"; 319 | outputPaths = ( 320 | "$(DERIVED_FILE_DIR)/Pods-EnumListProjectTests-checkManifestLockResult.txt", 321 | ); 322 | runOnlyForDeploymentPostprocessing = 0; 323 | shellPath = /bin/sh; 324 | 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"; 325 | showEnvVarsInLog = 0; 326 | }; 327 | D4395D8B24F7173161A0A6B8 /* [CP] Check Pods Manifest.lock */ = { 328 | isa = PBXShellScriptBuildPhase; 329 | buildActionMask = 2147483647; 330 | files = ( 331 | ); 332 | inputPaths = ( 333 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 334 | "${PODS_ROOT}/Manifest.lock", 335 | ); 336 | name = "[CP] Check Pods Manifest.lock"; 337 | outputPaths = ( 338 | "$(DERIVED_FILE_DIR)/Pods-EnumListProject-checkManifestLockResult.txt", 339 | ); 340 | runOnlyForDeploymentPostprocessing = 0; 341 | shellPath = /bin/sh; 342 | 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"; 343 | showEnvVarsInLog = 0; 344 | }; 345 | FD756022EE3702EAE02C32ED /* [CP] Embed Pods Frameworks */ = { 346 | isa = PBXShellScriptBuildPhase; 347 | buildActionMask = 2147483647; 348 | files = ( 349 | ); 350 | inputPaths = ( 351 | ); 352 | name = "[CP] Embed Pods Frameworks"; 353 | outputPaths = ( 354 | ); 355 | runOnlyForDeploymentPostprocessing = 0; 356 | shellPath = /bin/sh; 357 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-EnumListProjectTests/Pods-EnumListProjectTests-frameworks.sh\"\n"; 358 | showEnvVarsInLog = 0; 359 | }; 360 | /* End PBXShellScriptBuildPhase section */ 361 | 362 | /* Begin PBXSourcesBuildPhase section */ 363 | 10005CC01F3F00F100DFB92D /* Sources */ = { 364 | isa = PBXSourcesBuildPhase; 365 | buildActionMask = 2147483647; 366 | files = ( 367 | 10005CCA1F3F00F100DFB92D /* ViewController.swift in Sources */, 368 | 10005CC81F3F00F100DFB92D /* AppDelegate.swift in Sources */, 369 | ); 370 | runOnlyForDeploymentPostprocessing = 0; 371 | }; 372 | 10005CD41F3F00F200DFB92D /* Sources */ = { 373 | isa = PBXSourcesBuildPhase; 374 | buildActionMask = 2147483647; 375 | files = ( 376 | 1092413D1F53037400076DCA /* EnumListEncodableTests.swift in Sources */, 377 | 10005CDD1F3F00F200DFB92D /* EnumListTests.swift in Sources */, 378 | 107498861F52E3D0004C5619 /* EnumListDecodableTests.swift in Sources */, 379 | 1056D5E21F3F17580084D044 /* EnumListUnboxTests.swift in Sources */, 380 | ); 381 | runOnlyForDeploymentPostprocessing = 0; 382 | }; 383 | /* End PBXSourcesBuildPhase section */ 384 | 385 | /* Begin PBXTargetDependency section */ 386 | 10005CDA1F3F00F200DFB92D /* PBXTargetDependency */ = { 387 | isa = PBXTargetDependency; 388 | target = 10005CC31F3F00F100DFB92D /* EnumListProject */; 389 | targetProxy = 10005CD91F3F00F200DFB92D /* PBXContainerItemProxy */; 390 | }; 391 | /* End PBXTargetDependency section */ 392 | 393 | /* Begin PBXVariantGroup section */ 394 | 10005CCB1F3F00F200DFB92D /* Main.storyboard */ = { 395 | isa = PBXVariantGroup; 396 | children = ( 397 | 10005CCC1F3F00F200DFB92D /* Base */, 398 | ); 399 | name = Main.storyboard; 400 | sourceTree = ""; 401 | }; 402 | 10005CD01F3F00F200DFB92D /* LaunchScreen.storyboard */ = { 403 | isa = PBXVariantGroup; 404 | children = ( 405 | 10005CD11F3F00F200DFB92D /* Base */, 406 | ); 407 | name = LaunchScreen.storyboard; 408 | sourceTree = ""; 409 | }; 410 | /* End PBXVariantGroup section */ 411 | 412 | /* Begin XCBuildConfiguration section */ 413 | 10005CDF1F3F00F200DFB92D /* Debug */ = { 414 | isa = XCBuildConfiguration; 415 | buildSettings = { 416 | ALWAYS_SEARCH_USER_PATHS = NO; 417 | CLANG_ANALYZER_NONNULL = YES; 418 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 419 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 420 | CLANG_CXX_LIBRARY = "libc++"; 421 | CLANG_ENABLE_MODULES = YES; 422 | CLANG_ENABLE_OBJC_ARC = YES; 423 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 424 | CLANG_WARN_BOOL_CONVERSION = YES; 425 | CLANG_WARN_COMMA = YES; 426 | CLANG_WARN_CONSTANT_CONVERSION = YES; 427 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 428 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 429 | CLANG_WARN_EMPTY_BODY = YES; 430 | CLANG_WARN_ENUM_CONVERSION = YES; 431 | CLANG_WARN_INFINITE_RECURSION = YES; 432 | CLANG_WARN_INT_CONVERSION = YES; 433 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 434 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 435 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 436 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 437 | CLANG_WARN_STRICT_PROTOTYPES = YES; 438 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 439 | CLANG_WARN_UNREACHABLE_CODE = YES; 440 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 441 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 442 | COPY_PHASE_STRIP = NO; 443 | DEBUG_INFORMATION_FORMAT = dwarf; 444 | ENABLE_STRICT_OBJC_MSGSEND = YES; 445 | ENABLE_TESTABILITY = YES; 446 | GCC_C_LANGUAGE_STANDARD = gnu99; 447 | GCC_DYNAMIC_NO_PIC = NO; 448 | GCC_NO_COMMON_BLOCKS = YES; 449 | GCC_OPTIMIZATION_LEVEL = 0; 450 | GCC_PREPROCESSOR_DEFINITIONS = ( 451 | "DEBUG=1", 452 | "$(inherited)", 453 | ); 454 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 455 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 456 | GCC_WARN_UNDECLARED_SELECTOR = YES; 457 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 458 | GCC_WARN_UNUSED_FUNCTION = YES; 459 | GCC_WARN_UNUSED_VARIABLE = YES; 460 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 461 | MTL_ENABLE_DEBUG_INFO = YES; 462 | ONLY_ACTIVE_ARCH = YES; 463 | SDKROOT = iphoneos; 464 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 465 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 466 | TARGETED_DEVICE_FAMILY = "1,2"; 467 | }; 468 | name = Debug; 469 | }; 470 | 10005CE01F3F00F200DFB92D /* Release */ = { 471 | isa = XCBuildConfiguration; 472 | buildSettings = { 473 | ALWAYS_SEARCH_USER_PATHS = NO; 474 | CLANG_ANALYZER_NONNULL = YES; 475 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 476 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 477 | CLANG_CXX_LIBRARY = "libc++"; 478 | CLANG_ENABLE_MODULES = YES; 479 | CLANG_ENABLE_OBJC_ARC = YES; 480 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 481 | CLANG_WARN_BOOL_CONVERSION = YES; 482 | CLANG_WARN_COMMA = YES; 483 | CLANG_WARN_CONSTANT_CONVERSION = YES; 484 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 485 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 486 | CLANG_WARN_EMPTY_BODY = YES; 487 | CLANG_WARN_ENUM_CONVERSION = YES; 488 | CLANG_WARN_INFINITE_RECURSION = YES; 489 | CLANG_WARN_INT_CONVERSION = YES; 490 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 491 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 492 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 493 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 494 | CLANG_WARN_STRICT_PROTOTYPES = YES; 495 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 496 | CLANG_WARN_UNREACHABLE_CODE = YES; 497 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 498 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 499 | COPY_PHASE_STRIP = NO; 500 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 501 | ENABLE_NS_ASSERTIONS = NO; 502 | ENABLE_STRICT_OBJC_MSGSEND = YES; 503 | GCC_C_LANGUAGE_STANDARD = gnu99; 504 | GCC_NO_COMMON_BLOCKS = YES; 505 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 506 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 507 | GCC_WARN_UNDECLARED_SELECTOR = YES; 508 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 509 | GCC_WARN_UNUSED_FUNCTION = YES; 510 | GCC_WARN_UNUSED_VARIABLE = YES; 511 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 512 | MTL_ENABLE_DEBUG_INFO = NO; 513 | SDKROOT = iphoneos; 514 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 515 | TARGETED_DEVICE_FAMILY = "1,2"; 516 | VALIDATE_PRODUCT = YES; 517 | }; 518 | name = Release; 519 | }; 520 | 10005CE21F3F00F200DFB92D /* Debug */ = { 521 | isa = XCBuildConfiguration; 522 | baseConfigurationReference = 5C2076FE89539B210F45DF0E /* Pods-EnumListProject.debug.xcconfig */; 523 | buildSettings = { 524 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 525 | INFOPLIST_FILE = EnumListProject/Info.plist; 526 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 527 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 528 | PRODUCT_BUNDLE_IDENTIFIER = com.polaczyk.EnumListProject; 529 | PRODUCT_NAME = "$(TARGET_NAME)"; 530 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 531 | SWIFT_VERSION = 4.0; 532 | }; 533 | name = Debug; 534 | }; 535 | 10005CE31F3F00F200DFB92D /* Release */ = { 536 | isa = XCBuildConfiguration; 537 | baseConfigurationReference = 14471477568D8E102EA85FC2 /* Pods-EnumListProject.release.xcconfig */; 538 | buildSettings = { 539 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 540 | INFOPLIST_FILE = EnumListProject/Info.plist; 541 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 542 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 543 | PRODUCT_BUNDLE_IDENTIFIER = com.polaczyk.EnumListProject; 544 | PRODUCT_NAME = "$(TARGET_NAME)"; 545 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 546 | SWIFT_VERSION = 4.0; 547 | }; 548 | name = Release; 549 | }; 550 | 10005CE51F3F00F200DFB92D /* Debug */ = { 551 | isa = XCBuildConfiguration; 552 | baseConfigurationReference = 74B0A481CC3EB74BC1D9C0AB /* Pods-EnumListProjectTests.debug.xcconfig */; 553 | buildSettings = { 554 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 555 | BUNDLE_LOADER = "$(TEST_HOST)"; 556 | INFOPLIST_FILE = EnumListProjectTests/Info.plist; 557 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 558 | PRODUCT_BUNDLE_IDENTIFIER = com.polaczyk.EnumListProjectTests; 559 | PRODUCT_NAME = "$(TARGET_NAME)"; 560 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 561 | SWIFT_VERSION = 4.0; 562 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/EnumListProject.app/EnumListProject"; 563 | }; 564 | name = Debug; 565 | }; 566 | 10005CE61F3F00F200DFB92D /* Release */ = { 567 | isa = XCBuildConfiguration; 568 | baseConfigurationReference = 1D5F875EA599999652412E30 /* Pods-EnumListProjectTests.release.xcconfig */; 569 | buildSettings = { 570 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 571 | BUNDLE_LOADER = "$(TEST_HOST)"; 572 | INFOPLIST_FILE = EnumListProjectTests/Info.plist; 573 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 574 | PRODUCT_BUNDLE_IDENTIFIER = com.polaczyk.EnumListProjectTests; 575 | PRODUCT_NAME = "$(TARGET_NAME)"; 576 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 577 | SWIFT_VERSION = 4.0; 578 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/EnumListProject.app/EnumListProject"; 579 | }; 580 | name = Release; 581 | }; 582 | /* End XCBuildConfiguration section */ 583 | 584 | /* Begin XCConfigurationList section */ 585 | 10005CBF1F3F00F100DFB92D /* Build configuration list for PBXProject "EnumListProject" */ = { 586 | isa = XCConfigurationList; 587 | buildConfigurations = ( 588 | 10005CDF1F3F00F200DFB92D /* Debug */, 589 | 10005CE01F3F00F200DFB92D /* Release */, 590 | ); 591 | defaultConfigurationIsVisible = 0; 592 | defaultConfigurationName = Release; 593 | }; 594 | 10005CE11F3F00F200DFB92D /* Build configuration list for PBXNativeTarget "EnumListProject" */ = { 595 | isa = XCConfigurationList; 596 | buildConfigurations = ( 597 | 10005CE21F3F00F200DFB92D /* Debug */, 598 | 10005CE31F3F00F200DFB92D /* Release */, 599 | ); 600 | defaultConfigurationIsVisible = 0; 601 | defaultConfigurationName = Release; 602 | }; 603 | 10005CE41F3F00F200DFB92D /* Build configuration list for PBXNativeTarget "EnumListProjectTests" */ = { 604 | isa = XCConfigurationList; 605 | buildConfigurations = ( 606 | 10005CE51F3F00F200DFB92D /* Debug */, 607 | 10005CE61F3F00F200DFB92D /* Release */, 608 | ); 609 | defaultConfigurationIsVisible = 0; 610 | defaultConfigurationName = Release; 611 | }; 612 | /* End XCConfigurationList section */ 613 | }; 614 | rootObject = 10005CBC1F3F00F100DFB92D /* Project object */; 615 | } 616 | -------------------------------------------------------------------------------- /Project/EnumListProject.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Project/EnumListProject.xcodeproj/xcshareddata/xcschemes/EnumListProject.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 35 | 41 | 42 | 43 | 44 | 45 | 51 | 52 | 53 | 54 | 55 | 56 | 67 | 69 | 75 | 76 | 77 | 78 | 79 | 80 | 86 | 88 | 94 | 95 | 96 | 97 | 99 | 100 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /Project/EnumListProject.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Project/EnumListProject/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // EnumListProject 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // Copyright © 2017 Bartosz Polaczyk. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Project/EnumListProject/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Project/EnumListProject/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Project/EnumListProject/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Project/EnumListProject/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Project/EnumListProject/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // EnumListProject 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // Copyright © 2017 Bartosz Polaczyk. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Project/EnumListProjectTests/EnumListDecodableTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumListCodableTests.swift 3 | // EnumListProjectTests 4 | // 5 | // Created by Bartosz Polaczyk on 27/08/2017. 6 | // Copyright © 2017 Bartosz Polaczyk. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import EnumList 11 | 12 | 13 | 14 | private enum SubjectString: EnumListStringRaw, RawRepresentable{ 15 | struct Values:StringEnumValues { 16 | typealias Element = SubjectString 17 | 18 | static var allRaws:Set = [] 19 | } 20 | 21 | case caseNo1 = "case1" 22 | case caseNo2 = "case2" 23 | } 24 | 25 | private enum SubjectInt: EnumListIntRaw, RawRepresentable{ 26 | struct Values:IntEnumValues { 27 | typealias Element = SubjectInt 28 | 29 | static var allRaws:Set = [] 30 | } 31 | 32 | case caseNo1 = 1 33 | case caseNo2 = 2 34 | } 35 | 36 | 37 | extension SubjectString:Decodable{} 38 | extension SubjectInt:Decodable{} 39 | 40 | 41 | class EnumListDecodableTests: XCTestCase { 42 | struct Subjects:Decodable, Equatable { 43 | static func ==(lhs: Subjects, rhs: Subjects) -> Bool { 44 | return lhs.subjectString == rhs.subjectString && lhs.subjectInt == rhs.subjectInt 45 | } 46 | 47 | fileprivate let subjectString:SubjectString 48 | fileprivate let subjectInt:SubjectInt 49 | } 50 | 51 | func testDecodesCorrectlyEnumListRaws(){ 52 | // Arrange 53 | let decoder = JSONDecoder() 54 | let json = """ 55 | { 56 | "subjectString": "case1", 57 | "subjectInt": 2 58 | } 59 | """.data(using: .utf8)! 60 | 61 | // Act 62 | let subjects = try? decoder.decode(Subjects.self, from: json) 63 | 64 | // Assert 65 | XCTAssertEqual(subjects, Subjects(subjectString: .caseNo1, subjectInt: .caseNo2)) 66 | } 67 | 68 | func testDecodingThrowsAnErrorWhenStringDataDoesNotCorrespondToEnum(){ 69 | // Arrange 70 | let decoder = JSONDecoder() 71 | let json = """ 72 | { 73 | "subjectString": "NON_EXISTING", 74 | "subjectInt": 2 75 | } 76 | """.data(using: .utf8)! 77 | 78 | // Act 79 | var errorObserved:Error? 80 | do{ 81 | _ = try decoder.decode(Subjects.self, from: json) 82 | }catch{ 83 | errorObserved = error 84 | } 85 | 86 | // Assert 87 | switch(errorObserved){ 88 | case .some(DecodingError.dataCorrupted): 89 | break 90 | default: XCTFail("Expecting dataCorrupted error") 91 | } 92 | } 93 | 94 | func testDecodingThrowsAnErrorWhenIntDataDoesNotCorrespondToEnum(){ 95 | // Arrange 96 | let decoder = JSONDecoder() 97 | let json = """ 98 | { 99 | "subjectString": "case1", 100 | "subjectInt": -1 101 | } 102 | """.data(using: .utf8)! 103 | 104 | // Act 105 | var errorObserved:Error? 106 | do{ 107 | _ = try decoder.decode(Subjects.self, from: json) 108 | }catch{ 109 | errorObserved = error 110 | } 111 | 112 | // Assert 113 | switch(errorObserved){ 114 | case .some(DecodingError.dataCorrupted): 115 | break 116 | default: XCTFail("Expecting dataCorrupted error") 117 | } 118 | } 119 | 120 | func testDecodingThrowsAnErrorWhenExpectedStringValueIsOtherType(){ 121 | // Arrange 122 | let decoder = JSONDecoder() 123 | let json = """ 124 | { 125 | "subjectString": 1, 126 | "subjectInt": 1 127 | } 128 | """.data(using: .utf8)! 129 | 130 | // Act 131 | var errorObserved:Error? 132 | do{ 133 | _ = try decoder.decode(Subjects.self, from: json) 134 | }catch{ 135 | errorObserved = error 136 | } 137 | 138 | // Assert 139 | switch(errorObserved){ 140 | case .some(DecodingError.typeMismatch): 141 | break 142 | default: XCTFail("Expecting typeMismatch error") 143 | } 144 | } 145 | 146 | func testDecodingThrowsAnErrorWhenExpectedIntValueIsOtherType(){ 147 | // Arrange 148 | let decoder = JSONDecoder() 149 | let json = """ 150 | { 151 | "subjectString": "case1", 152 | "subjectInt": "nonNumber" 153 | } 154 | """.data(using: .utf8)! 155 | 156 | // Act 157 | var errorObserved:Error? 158 | do{ 159 | _ = try decoder.decode(Subjects.self, from: json) 160 | }catch{ 161 | errorObserved = error 162 | } 163 | 164 | // Assert 165 | switch(errorObserved){ 166 | case .some(DecodingError.typeMismatch): 167 | break 168 | default: XCTFail("Expecting typeMismatch error") 169 | } 170 | } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /Project/EnumListProjectTests/EnumListEncodableTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumListEncodableTests.swift 3 | // EnumListProjectTests 4 | // 5 | // Created by Bartosz Polaczyk on 27/08/2017. 6 | // Copyright © 2017 Bartosz Polaczyk. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import EnumList 11 | 12 | 13 | 14 | private enum SubjectString: EnumListStringRaw, RawRepresentable{ 15 | struct Values:StringEnumValues { 16 | typealias Element = SubjectString 17 | 18 | static var allRaws:Set = [] 19 | } 20 | 21 | case caseNo1 = "case1" 22 | case caseNo2 = "case2" 23 | } 24 | 25 | private enum SubjectInt: EnumListIntRaw, RawRepresentable{ 26 | struct Values:IntEnumValues { 27 | typealias Element = SubjectInt 28 | 29 | static var allRaws:Set = [] 30 | } 31 | 32 | case caseNo1 = 1 33 | case caseNo2 = 2 34 | } 35 | 36 | 37 | extension SubjectString:Codable{} 38 | extension SubjectInt:Codable{} 39 | 40 | 41 | class EnumListEncodableTests: XCTestCase { 42 | struct Subjects:Codable, Equatable { 43 | static func ==(lhs: Subjects, rhs: Subjects) -> Bool { 44 | return lhs.subjectString == rhs.subjectString && lhs.subjectInt == rhs.subjectInt 45 | } 46 | 47 | fileprivate let subjectString:SubjectString 48 | fileprivate let subjectInt:SubjectInt 49 | } 50 | 51 | struct OptionalSubjects:Codable, Equatable { 52 | static func ==(lhs: OptionalSubjects, rhs: OptionalSubjects) -> Bool { 53 | return lhs.subjectString == rhs.subjectString && lhs.subjectInt == rhs.subjectInt 54 | } 55 | 56 | fileprivate let subjectString:SubjectString? 57 | fileprivate let subjectInt:SubjectInt? 58 | } 59 | 60 | func testDecodesCorrectlyEnumListRaws() throws{ 61 | // Arrange 62 | let encoder = JSONEncoder() 63 | let decoder = JSONDecoder() 64 | let subjects = Subjects(subjectString: .caseNo1, subjectInt: .caseNo2) 65 | 66 | // Act 67 | let subjectsData:Data 68 | do{ 69 | subjectsData = try encoder.encode(subjects) 70 | }catch{ 71 | XCTFail("Unexpected errorr") 72 | throw error 73 | } 74 | 75 | // Assert 76 | try XCTAssertEqual(subjects, decoder.decode(Subjects.self, from: subjectsData)) 77 | } 78 | 79 | func testDecodesCorrectlyOptionalEnumListRaws() throws{ 80 | // Arrange 81 | let encoder = JSONEncoder() 82 | let decoder = JSONDecoder() 83 | let subjects = OptionalSubjects(subjectString: .caseNo1, subjectInt: .caseNo2) 84 | 85 | // Act 86 | let subjectsData:Data 87 | do{ 88 | subjectsData = try encoder.encode(subjects) 89 | }catch{ 90 | XCTFail("Unexpected errorr") 91 | throw error 92 | } 93 | 94 | // Assert 95 | try XCTAssertEqual(subjects, decoder.decode(OptionalSubjects.self, from: subjectsData)) 96 | } 97 | 98 | func testDecodesCorrectlyNilEnumListRaws() throws{ 99 | // Arrange 100 | let encoder = JSONEncoder() 101 | let decoder = JSONDecoder() 102 | let subjects = OptionalSubjects(subjectString: nil, subjectInt: nil) 103 | 104 | // Act 105 | let subjectsData:Data 106 | do{ 107 | subjectsData = try encoder.encode(subjects) 108 | }catch{ 109 | XCTFail("Unexpected errorr") 110 | throw error 111 | } 112 | 113 | // Assert 114 | try XCTAssertEqual(subjects, decoder.decode(OptionalSubjects.self, from: subjectsData)) 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /Project/EnumListProjectTests/EnumListTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumListProjectTests.swift 3 | // EnumListProjectTests 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // Copyright © 2017 Bartosz Polaczyk. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import EnumList 11 | 12 | class EnumListTests: XCTestCase { 13 | 14 | private enum SubjectString: EnumListStringRaw, RawRepresentable{ 15 | struct Values:StringEnumValues { 16 | typealias Element = SubjectString 17 | 18 | static var allRaws:Set = [] 19 | } 20 | 21 | case caseNo1 = "case1" 22 | case caseNo2 = "case2" 23 | } 24 | 25 | private enum SubjectStringDefaultValue: EnumListStringRaw, RawRepresentable{ 26 | struct Values:StringEnumValues { 27 | typealias Element = SubjectStringDefaultValue 28 | 29 | static var allRaws:Set = [] 30 | } 31 | 32 | case caseNo1 33 | case caseNo2 = "case2" 34 | } 35 | 36 | private enum SubjectInt: EnumListIntRaw, RawRepresentable{ 37 | struct Values:IntEnumValues { 38 | typealias Element = SubjectInt 39 | 40 | static var allRaws:Set = [] 41 | } 42 | 43 | case caseNo1 = 1 44 | case caseNo2 = 200 45 | } 46 | 47 | 48 | func testInitializingFromStringSucceeds(){ 49 | XCTAssertEqual(SubjectString(rawValue: "case1"), .caseNo1) 50 | } 51 | func testInitializingFromUnknownStringReturnsNil(){ 52 | XCTAssertNil(SubjectString(rawValue: "!NON_EXISTING!")) 53 | } 54 | func testInitializingFromIntSucceeds(){ 55 | XCTAssertEqual(SubjectInt(rawValue: 200), .caseNo2) 56 | } 57 | func testInitializingFromUnknownIntReturnsNil(){ 58 | XCTAssertNil(SubjectInt(rawValue: -1)) 59 | } 60 | 61 | func testInitializingFromStringVariableSucceeds(){ 62 | // Arrange 63 | let string = "case1" 64 | 65 | // Act 66 | let subject = SubjectString(raw: string) 67 | 68 | // Assert 69 | XCTAssertEqual(subject, .caseNo1) 70 | } 71 | func testInitializingFromIntVariableSucceeds(){ 72 | // Arrange 73 | let intValue = 200 74 | 75 | // Act 76 | let subject = SubjectInt.init(raw: intValue) 77 | 78 | // Assert 79 | XCTAssertEqual(subject, .caseNo2) 80 | } 81 | 82 | func testInitializingWithCustomInitFromLiteralStringSucceeds(){ 83 | XCTAssertEqual(SubjectString(raw: "case1"), .caseNo1) 84 | } 85 | func testInitializingWithCustomInitFromLiteralIntSucceeds(){ 86 | XCTAssertEqual(SubjectInt(raw: 200), .caseNo2) 87 | } 88 | 89 | func testStringRawCreatesFromGraphemeLiteral(){ 90 | // Arrange 91 | let stringRaw = EnumListStringRaw(extendedGraphemeClusterLiteral: "case1") 92 | 93 | // Act 94 | let subject = SubjectString(rawValue: stringRaw) 95 | 96 | // Assert 97 | XCTAssertEqual(subject, .caseNo1) 98 | } 99 | func testStringRawCreatesFromUnicodeLiteral(){ 100 | // Arrange 101 | let stringRaw = EnumListStringRaw(unicodeScalarLiteral: "case1") 102 | 103 | // Act 104 | let subject = SubjectString(rawValue: stringRaw) 105 | 106 | // Assert 107 | XCTAssertEqual(subject, .caseNo1) 108 | } 109 | 110 | func testAllStringEnumsExistInAllList(){ 111 | // Arrange 112 | 113 | // Act 114 | let allValues = SubjectString.Values.all 115 | let allRawValues = SubjectString.Values.allRawValues 116 | // Assert 117 | XCTAssertEqual(allValues, Set([.caseNo1, .caseNo2])) 118 | XCTAssertEqual(allRawValues, Set(["case1", "case2"])) 119 | } 120 | 121 | func testAllRawStringValuesExistInAllRaws(){ 122 | // Arrange 123 | 124 | // Act 125 | _ = SubjectString.Values.all 126 | let allRaws = SubjectString.Values.allRaws 127 | // Assert 128 | XCTAssertEqual(allRaws, Set(["case1", "case2"])) 129 | } 130 | 131 | func testNotCallingAllBeforeAskingForAllRawsReturnsEmptySet(){ 132 | enum PrivateSubject: EnumListStringRaw, RawRepresentable{ 133 | struct Values:StringEnumValues { 134 | typealias Element = PrivateSubject 135 | 136 | static var allRaws:Set = [] 137 | } 138 | 139 | case caseNo1 = "case1" 140 | case caseNo2 = "case2" 141 | } 142 | 143 | // Arrange 144 | 145 | // Act 146 | let allRaws = PrivateSubject.Values.allRaws 147 | // Assert 148 | XCTAssertTrue(allRaws.isEmpty) 149 | } 150 | 151 | func testFetchingNonExistingEnumFillsAllRawsSet(){ 152 | enum PrivateSubject: EnumListStringRaw, RawRepresentable{ 153 | struct Values:StringEnumValues { 154 | typealias Element = PrivateSubject 155 | 156 | static var allRaws:Set = [] 157 | } 158 | 159 | case caseNo1 = "case1" 160 | case caseNo2 = "case2" 161 | } 162 | 163 | // Arrange 164 | let raw:EnumListStringRaw = "some_none_existing_raw" 165 | // Act 166 | _ = PrivateSubject(rawValue: raw) 167 | 168 | // Assert 169 | let allRaws = PrivateSubject.Values.allRaws 170 | XCTAssertFalse(allRaws.isEmpty) 171 | } 172 | 173 | func testComparingDifferentEnumListRawsDoesNotModifyRawsSet(){ 174 | enum PrivateSubject: EnumListStringRaw, RawRepresentable{ 175 | struct Values:StringEnumValues { 176 | typealias Element = PrivateSubject 177 | 178 | static var allRaws:Set = [] 179 | } 180 | 181 | case caseNo1 = "case1" 182 | case caseNo2 = "case2" 183 | } 184 | 185 | // Arrange 186 | let raw:EnumListStringRaw = "some_none_existing_raw" 187 | // Act 188 | _ = PrivateSubject.caseNo1.rawValue == raw 189 | 190 | // Assert 191 | let allRaws = PrivateSubject.Values.allRaws 192 | XCTAssertFalse(allRaws.isEmpty) 193 | } 194 | 195 | func testAskingForInitializationFillsAllRawsSet(){ 196 | enum PrivateSubject: EnumListStringRaw, RawRepresentable{ 197 | struct Values:StringEnumValues { 198 | typealias Element = PrivateSubject 199 | 200 | static var allRaws:Set = [] 201 | } 202 | 203 | case caseNo1 = "case1" 204 | case caseNo2 = "case2" 205 | } 206 | 207 | // Arrange 208 | 209 | // Act 210 | _ = PrivateSubject.Values.all 211 | 212 | // Assert 213 | let allRaws = PrivateSubject.Values.allRaws 214 | XCTAssertFalse(allRaws.isEmpty) 215 | } 216 | 217 | 218 | func testAllIntEnumsExistInAllList(){ 219 | // Arrange 220 | 221 | // Act 222 | let allValues = SubjectInt.Values.all 223 | let allRawValues = SubjectInt.Values.allRawValues 224 | // Assert 225 | XCTAssertEqual(allValues, Set([.caseNo1, .caseNo2])) 226 | XCTAssertEqual(allRawValues, Set([1, 200])) 227 | } 228 | 229 | func testAllRawIntValuesExistInAllRaws(){ 230 | // Arrange 231 | 232 | // Act 233 | _ = SubjectInt.Values.all 234 | let allRaws = SubjectInt.Values.allRaws 235 | // Assert 236 | XCTAssertEqual(allRaws, Set([1, 200])) 237 | } 238 | 239 | func testStringInitializationClearsASet(){ 240 | // Arrange 241 | SubjectString.Values.allRaws = ["X"] 242 | 243 | // Act 244 | _ = SubjectString.Values.all 245 | 246 | // Assert 247 | let allRaws = SubjectString.Values.allRaws 248 | XCTAssertEqual(allRaws, Set(["case1", "case2"])) 249 | } 250 | 251 | func testIntInitializationClearsASet(){ 252 | // Arrange 253 | SubjectInt.Values.allRaws = [111] 254 | 255 | // Act 256 | _ = SubjectInt.Values.all 257 | 258 | // Assert 259 | let allRaws = SubjectInt.Values.allRaws 260 | XCTAssertEqual(allRaws, Set([1,200])) 261 | } 262 | 263 | func testStringableSetReturnedIsCreatedFromScratch(){ 264 | // Arrange 265 | SubjectString.Values.allRaws = ["X"] 266 | 267 | // Act 268 | 269 | // Assert 270 | let allRaws = SubjectString.Values.all 271 | XCTAssertEqual(allRaws, Set([.caseNo1, .caseNo2])) 272 | } 273 | 274 | func testInterableSetReturnedIsCreatedFromScratch(){ 275 | // Arrange 276 | SubjectInt.Values.allRaws = [111] 277 | 278 | // Act 279 | let allRaws = SubjectInt.Values.all 280 | let allRawValues = SubjectInt.Values.allRawValues 281 | // Assert 282 | 283 | XCTAssertEqual(allRaws, Set([.caseNo1, .caseNo2])) 284 | XCTAssertEqual(allRawValues, Set([1, 200])) 285 | } 286 | 287 | func testAllValuesForEnumWithDefaultStringVariableAreValid(){ 288 | XCTAssertEqual(SubjectStringDefaultValue.Values.all, [.caseNo1, .caseNo2]) 289 | XCTAssertEqual(SubjectStringDefaultValue.Values.allRawValues, ["caseNo1", "case2"]) 290 | } 291 | func testAllRawValuesForEnumWithDefaultStringVariableAreValid(){ 292 | // Arrange 293 | _ = SubjectStringDefaultValue.Values.all 294 | // Act 295 | XCTAssertEqual(SubjectStringDefaultValue.Values.allRaws, ["caseNo1", "case2"]) 296 | } 297 | 298 | } 299 | -------------------------------------------------------------------------------- /Project/EnumListProjectTests/EnumListUnboxTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumListUnboxTests.swift 3 | // EnumListProject 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // Copyright © 2017 Bartosz Polaczyk. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import EnumList 11 | import Unbox 12 | 13 | class EnumListUnboxTests: XCTestCase { 14 | 15 | private enum SubjectString: EnumListStringRaw, RawRepresentable, UnboxableEnum{ 16 | struct Values:StringEnumValues { 17 | typealias Element = SubjectString 18 | 19 | static var allRaws:Set = [] 20 | } 21 | 22 | case caseNo1 = "case1" 23 | case caseNo2 = "case2" 24 | } 25 | 26 | private enum SubjectInt: EnumListIntRaw, RawRepresentable, UnboxableEnum{ 27 | struct Values:IntEnumValues { 28 | typealias Element = SubjectInt 29 | 30 | static var allRaws:Set = [] 31 | } 32 | 33 | case caseNo1 = 1 34 | case caseNo2 = 200 35 | } 36 | 37 | 38 | func testUnboxingDoesNotBreakListingAllsEnums() throws { 39 | // Arrange 40 | let dictionary:[String:Any] = ["data":"case1"] 41 | let a = Unboxer(dictionary:dictionary) 42 | let _:SubjectString = try a.unbox(key: "data") 43 | 44 | // Act 45 | let all = SubjectString.Values.all 46 | let allRawValues = SubjectString.Values.allRawValues 47 | 48 | // Assert 49 | XCTAssertEqual(all, [.caseNo1, .caseNo2]) 50 | XCTAssertEqual(allRawValues, ["case1", "case2"]) 51 | } 52 | 53 | func testUnboxingStringFindsEnum() throws { 54 | // Arrange 55 | let dictionary:[String:Any] = ["data":"case1"] 56 | 57 | // Act 58 | let a = Unboxer(dictionary:dictionary) 59 | let unboxed:SubjectString = try a.unbox(key: "data") 60 | 61 | // Assert 62 | XCTAssertEqual(unboxed, .caseNo1) 63 | } 64 | 65 | func testUnboxingStringFailsForIntValueInDict() throws { 66 | // Arrange 67 | let dictionary:[String:Any] = ["data":1] 68 | 69 | // Act 70 | let a = Unboxer(dictionary:dictionary) 71 | let unboxed:SubjectString? = try? a.unbox(key: "data") 72 | 73 | // Assert 74 | XCTAssertNil(unboxed) 75 | } 76 | 77 | func testUnboxingIntEnumSucceeds() throws { 78 | // Arrange 79 | let dictionary:[String:Any] = ["data":1] 80 | 81 | // Act 82 | let a = Unboxer(dictionary:dictionary) 83 | let unboxed:SubjectInt = try a.unbox(key: "data") 84 | 85 | // Assert 86 | XCTAssertEqual(unboxed, .caseNo1) 87 | } 88 | 89 | func testUnboxingSecondIntEnumSucceeds() throws { 90 | // Arrange 91 | let dictionary:[String:Any] = ["data":200] 92 | 93 | // Act 94 | let a = Unboxer(dictionary:dictionary) 95 | let unboxed:SubjectInt = try a.unbox(key: "data") 96 | 97 | // Assert 98 | XCTAssertEqual(unboxed, .caseNo2) 99 | } 100 | 101 | func testUnboxingIntEnumFromUnknownValueFails() throws { 102 | // Arrange 103 | let dictionary:[String:Any] = ["data":-1] 104 | 105 | // Act 106 | let a = Unboxer(dictionary:dictionary) 107 | let unboxed:SubjectInt? = try? a.unbox(key: "data") 108 | 109 | // Assert 110 | XCTAssertNil(unboxed) 111 | } 112 | 113 | func testUnboxingIntEnumFromStringFails() throws { 114 | // Arrange 115 | let dictionary:[String:Any] = ["data":"1"] 116 | 117 | // Act 118 | let a = Unboxer(dictionary:dictionary) 119 | let unboxed:SubjectInt? = try? a.unbox(key: "data") 120 | 121 | // Assert 122 | XCTAssertNil(unboxed) 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Project/EnumListProjectTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Project/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '9.0' 2 | 3 | target 'EnumListProject' do 4 | use_frameworks! 5 | 6 | pod 'EnumList', :path => '../' 7 | 8 | target 'EnumListProjectTests' do 9 | inherit! :search_paths 10 | end 11 | 12 | end 13 | -------------------------------------------------------------------------------- /Project/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - EnumList (0.2.0): 3 | - EnumList/Core (= 0.2.0) 4 | - EnumList/Unbox (= 0.2.0) 5 | - EnumList/Core (0.2.0): 6 | - Unbox (~> 2.5.0) 7 | - EnumList/Unbox (0.2.0): 8 | - Unbox (~> 2.5.0) 9 | - Unbox (2.5.0) 10 | 11 | DEPENDENCIES: 12 | - EnumList (from `../`) 13 | 14 | EXTERNAL SOURCES: 15 | EnumList: 16 | :path: ../ 17 | 18 | SPEC CHECKSUMS: 19 | EnumList: a0c627f81942d72488d0c8945e8cf7ff2edc1651 20 | Unbox: 30e437e6151a6de16139375fd4e8dd9a664cfbf7 21 | 22 | PODFILE CHECKSUM: 3df556e0604db7a0e2e9baab321ffa0c43e12966 23 | 24 | COCOAPODS: 1.3.1 25 | -------------------------------------------------------------------------------- /Project/fastlane/Fastfile: -------------------------------------------------------------------------------- 1 | fastlane_version "2.35.1" 2 | 3 | default_platform :ios 4 | 5 | platform :ios do 6 | before_all do 7 | cocoapods 8 | end 9 | 10 | desc "Runs all the tests" 11 | lane :test do 12 | scan(scheme: "EnumListProject", output_directory: "output/tests") 13 | xcov(scheme: "EnumListProject", workspace: "EnumListProject.xcworkspace", json_report: true, markdown_report: true, output_directory: "output/coverage/xcov", skip_slack: true, include_targets:"EnumList.framework", coveralls_service_name:"travis-ci", coveralls_service_job_id:ENV["TRAVIS_JOB_ID"]) 14 | #slather(proj: "EnumListProject.xcodeproj", workspace:"EnumListProject.xcworkspace",coveralls:true) 15 | end 16 | 17 | 18 | after_all do |lane| 19 | # This block is called, only if the executed lane was successful 20 | 21 | # slack( 22 | # message: "Successfully deployed new App Update." 23 | # ) 24 | end 25 | 26 | error do |lane, exception| 27 | # slack( 28 | # message: exception.message, 29 | # success: false 30 | # ) 31 | end 32 | end 33 | 34 | -------------------------------------------------------------------------------- /Project/fastlane/README.md: -------------------------------------------------------------------------------- 1 | fastlane documentation 2 | ================ 3 | # Installation 4 | 5 | Make sure you have the latest version of the Xcode command line tools installed: 6 | 7 | ``` 8 | xcode-select --install 9 | ``` 10 | 11 | ## Choose your installation method: 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
Homebrew 16 | Installer Script 17 | Rubygems 18 |
macOSmacOSmacOS or Linux with Ruby 2.0.0 or above
brew cask install fastlaneDownload the zip file. Then double click on the install script (or run it in a terminal window).sudo gem install fastlane -NV
30 | 31 | # Available Actions 32 | ## iOS 33 | ### ios test 34 | ``` 35 | fastlane ios test 36 | ``` 37 | Runs all the tests 38 | 39 | ---- 40 | 41 | This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run. 42 | More information about fastlane can be found on [fastlane.tools](https://fastlane.tools). 43 | The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools). 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EnumList 2 | 3 | [![Build Status][build-badge]][build-url] 4 | [![Coverage Status][codecov-badge]][codecov-url] 5 | [![CocoaPods][cocoapods-badge]][cocoapods-url] 6 | [![CocoaPodsPlatform][cocoapods-platform-badge]][cocoapods-platform-url] 7 | [![Fastlane][fastlane-badge]][fastlane-url] 8 | [![Swift][swift-badge]][swift-url] 9 | [![License][mit-badge]][mit-url] 10 | 11 | 12 | Library to enumerate all enum cases (for `String` or `Int` `RawValue`). 13 | 14 | EnumList does not relay non memory introspection so it is safe by design and becomes stable in the future Swift releases. 15 | 16 | 17 | ## Swift versions 18 | 19 | This branch works officially with Swift 4. 20 | 21 | If you want to use Swift 3 please check [`swift3` branch](https://github.com/polac24/EnumList/tree/swift3) and cocoapods version v0.1.x. 22 | 23 | ## Installation 24 | 25 | ### CocoaPods 26 | 27 | Use [CocoaPods](http://cocoapods.org) to install it with the following command: 28 | 29 | ```bash 30 | $ gem install cocoapods 31 | ``` 32 | 33 | To integrate `EnumList` into your project, specify it in your `Podfile`: 34 | 35 | ```ruby 36 | source 'https://github.com/CocoaPods/Specs.git' 37 | platform :ios, '9.0' 38 | use_frameworks! 39 | 40 | target 'TARGET' do 41 | pod 'EnumList/Core' 42 | end 43 | ``` 44 | 45 | Then, run the following command: 46 | 47 | ```bash 48 | $ pod install 49 | ``` 50 | 51 | ### Prerequisites 52 | 53 | In order to make your `enum` (with `String` rawValue) compatible with `EnumList`, add conformance to protocols `EnumListStringRaw, RawRepresentable` and define nested struct `Values`. 54 | 55 | *Althouh you have free choose the name and place to define `struct` that conformances to `StringEnumValues` or `IntEnumValues` (e.g. `YourEnumName.Values`), it is recommended to keep it as a nested type.* 56 | 57 | ```swift 58 | private enum YourEnumName: EnumListStringRaw, RawRepresentable{ 59 | struct Values:StringEnumValues { 60 | typealias Element = YourEnumName 61 | static var allRaws:Set = [] 62 | } 63 | case caseNo1 = "case1" 64 | case caseNo2 = "case2" 65 | //case caseNo3 = "case2" - compile error: RawValues have to be unique 66 | } 67 | 68 | YourEnumName.Values.all // Set([.caseNo1, .caseNo2]) 69 | YourEnumName.Values.allRaws // Set(["case1", "case2"]) 70 | 71 | ``` 72 | 73 | All your cases exist in static `Set` variable `YourEnumName.Values.all. 74 | 75 | ### Creating enum 76 | 77 | #### Enum from a literal 78 | 79 | You can still create your `enum` instance as previously, with literal intialization `init?(rawValue:)`: 80 | 81 | ```swift 82 | let myCase = YourEnumName(rawValue: "case1") // myCase = .caseNo1 83 | ``` 84 | 85 | #### Enum from a String variable 86 | 87 | If you cannot use literals (e.g. when you have only `String` instance passed you from somewhere else), you can create it using `init?(raw:)` initializer: 88 | 89 | ```swift 90 | let someString = "case1" 91 | ... 92 | let myCase = YourEnumName(raw: someString) // myCase = .caseNo1 93 | let myOtherCase = YourEnumName(raw: "case1") // myOtherCase = .caseNo1 94 | ``` 95 | 96 | ### Enums with `Int` RawValue 97 | 98 | `EnumList` works the same when dealing with `Int` rawValues: 99 | 100 | ```swift 101 | private enum YourIntEnum: EnumListIntRaw, RawRepresentable{ 102 | struct Values:IntEnumValues { 103 | typealias Element = YourIntEnum 104 | static var allRaws:Set = [] 105 | } 106 | case caseNo1 = 1 107 | case caseNo2 = 3 108 | } 109 | 110 | YourIntEnum.Values.all // Set([.caseNo1, .caseNo2]) 111 | YourIntEnum.Values.allRaws // Set([1, 2]) 112 | 113 | let myCase = YourIntEnum(rawValue: 1) // .caseNo1 114 | 115 | ``` 116 | 117 | ### Enums with "Default" RawValue 118 | 119 | Same as with standard `enum`, you don't need to specify all rawValues manually. Compiler will fill it for you, with the same `String` raw values, as a name of a case. You can mix cases with custom/automatic `rawValue`: 120 | 121 | ```swift 122 | private enum YourEnumName: EnumListStringRaw, RawRepresentable{ 123 | struct Values:StringEnumValues { 124 | typealias Element = YourEnumName 125 | static var allRaws:Set = [] 126 | } 127 | case caseNo1 // is equivalent to case caseNo1 = "caseNo1" 128 | case caseNo2 = "case2" 129 | } 130 | 131 | YourEnumName.Values.all // Set([.caseNo1, .caseNo2]) 132 | YourEnumName.Values.allRaws // Set(["caseNo1", "case2"]) 133 | 134 | ``` 135 | 136 | 137 | ### All Raw Values 138 | 139 | `YourEnumName.Values.allRawValues` for grabing all raw values (which are a `Set` or `Set`, depending of your `enum` deifinition). 140 | **Note:** `YourEnumName.Values.initialize()` or `YourEnumName.Values.all` are not required to call before anymore. 141 | 142 | ### Safety 143 | 144 | Swift does not allow to create several `enum` cases with same literal. It applies also for `EnumList`: 145 | 146 | ```swift 147 | private enum YourEnumName: EnumListStringRaw, RawRepresentable{ 148 | struct Values:StringEnumValues { 149 | typealias Element = YourEnumName 150 | static var allRaws:Set = [] 151 | } 152 | case caseNo1 = "case1" 153 | //case caseNo2 = "case1" - compile error: RawValues have to be unique 154 | } 155 | ``` 156 | 157 | ### Swift 4 compatibility 158 | 159 | `EnumList` is compatible with Swift4 out-of-the box. 160 | 161 | In addition, it supports `Codable` protocol as seamlessly as "normal" enums --- just add conformance to `Codable` (or separatelly `Encodable` and/or `Decodable`): 162 | ```swift 163 | private enum YourEnumName: EnumListStringRaw, RawRepresentable, Codable{ 164 | struct Values:StringEnumValues { 165 | typealias Element = YourEnumName 166 | static var allRaws:Set = [] 167 | } 168 | case caseNo1 = "case1" 169 | case caseNo2 = "case2" 170 | } 171 | ``` 172 | 173 | ### Integration with [Unbox](https://github.com/JohnSundell/Unbox) 174 | 175 | If you want use your `enum` with [`Unbox`](https://github.com/JohnSundell/Unbox) framework, include additional subspec, `EnumList/Unbox` to your `Podfile`: 176 | 177 | ```ruby 178 | target 'TARGET' do 179 | pod 'EnumList/Core' 180 | pod 'EnumList/Unbox' 181 | end 182 | ``` 183 | 184 | then by conforming your enum to `UnboxableEnum`, it works out of a box: 185 | 186 | ```swift 187 | private enum EnumForUnbox: EnumListStringRaw, RawRepresentable, UnboxableEnum{ 188 | struct Values:StringEnumValues { 189 | typealias Element = EnumForUnbox 190 | static var allRaws:Set = [] 191 | } 192 | case caseNo1 = "case1" 193 | case caseNo2 = "case2" 194 | } 195 | 196 | let dictionary:[String:Any] = ["data":"case1"] 197 | let a = Unboxer(dictionary:dictionary) 198 | let unboxEnum:EnumForUnbox = try a.unbox(key: "data") // .caseNo1 199 | ``` 200 | 201 | ## Running the tests 202 | 203 | ### Xcode 204 | Library is covered with unit tests: to run tests integrated with `EnumListPoroject.xcodeworkspace` project: install all CocoaPods dependencies (`pod install` in your terminal) and run default unit tests (⌘+U). 205 | 206 | ### Fastlane 207 | 208 | To test all unit tests from a commandline, call 'fastlane test' in the `Project` directory. 209 | 210 | ## Deployment 211 | 212 | Use `fastlane` to build a project: [fastlane Readme](Project/fastlane/) 213 | 214 | ## Versioning 215 | 216 | We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/polac24/EnumList/tags). 217 | 218 | ## How does it work? 219 | 220 | `EnumList` relies on a fact that that if we try to initialise an enum using `init(rawValue:)`, Swift takes all values of its `RawRepresentable` (that have corresponding `case`) one by one and compare it with your `rawValue`, until finds equal value. Therefore, if we try to initialise with some `rawValue` that does not match any case, `EnumList` will have a chance to gather all rawValues with corresponding enum inside `==` operator implementation. This library provides generic struct (`String` or `Int` representable) that you define as dedicated `RawRepresentable` type for your enum. 221 | 222 | You can find details in the following [document](https://medium.com/@londeix/listing-all-cases-in-an-enum-3b057f2c1432). 223 | 224 | ## Authors 225 | 226 | * **Bartosz Polaczyk** - [polac24](https://github.com/polac24) 227 | 228 | See also the list of [contributors](https://github.com/polac24/EnumList/contributors) who participated in this project. 229 | 230 | ## License 231 | 232 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details 233 | 234 | 235 | 236 | [swift-badge]: https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat 237 | [swift-url]: https://swift.org 238 | 239 | [mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat 240 | [mit-url]: https://tldrlegal.com/license/mit-license 241 | 242 | [build-badge]: https://img.shields.io/travis/polac24/EnumList.svg?maxAge=0 243 | [build-url]: https://travis-ci.org/polac24/EnumList 244 | 245 | [codecov-badge]: https://img.shields.io/coveralls/polac24/EnumList.svg?maxAge=0 246 | [codecov-url]: https://coveralls.io/github/polac24/EnumList 247 | 248 | [fastlane-badge]: https://img.shields.io/badge/fastlane-2.35.1-yellow.svg 249 | [fastlane-url]: Project/fastlane/Fastfile 250 | 251 | [cocoapods-badge]: https://img.shields.io/cocoapods/v/EnumList.svg?maxAge=0 252 | [cocoapods-url]: https://cocoapods.org/pods/EnumList 253 | 254 | [cocoapods-platform-badge]: https://img.shields.io/cocoapods/p/EnumList.svg?maxAge=0 255 | [cocoapods-platform-url]: https://cocoapods.org/pods/EnumList 256 | -------------------------------------------------------------------------------- /Sources/APIConvenience.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APIConvenience.swift 3 | // Pods 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | public extension RawRepresentable{ 13 | init?(raw rawValue: String) where RawValue == EnumListStringRaw{ 14 | self.init(rawValue: RawValue(stringLiteral: rawValue)) 15 | } 16 | } 17 | public extension RawRepresentable{ 18 | init?(raw rawValue: Int) where RawValue == EnumListIntRaw{ 19 | self.init(rawValue: EnumListIntRaw(integerLiteral: rawValue)) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/EnumListRaw.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumListRawRepresentable.swift 3 | // Pods 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // 7 | // 8 | 9 | import Foundation 10 | 11 | public protocol EnumListStringRawable{ 12 | init(stringLiteral value: String) 13 | var value:String? {get} 14 | } 15 | 16 | public struct EnumListStringRaw: EnumListStringRawable, ExpressibleByStringLiteral, Equatable{ 17 | public var value: String?{ 18 | return a 19 | } 20 | 21 | let a:String? 22 | 23 | public static func ==(lhs: EnumListStringRaw, rhs: EnumListStringRaw) -> Bool { 24 | if let lhsA = lhs.a { T.allRaws.insert(lhsA)} 25 | if let rhsA = rhs.a { T.allRaws.insert(rhsA)} 26 | 27 | return lhs.a == rhs.a 28 | } 29 | 30 | public init(stringLiteral value: String){ 31 | a = value 32 | } 33 | public init(extendedGraphemeClusterLiteral value: String){ 34 | a = value 35 | } 36 | public init(unicodeScalarLiteral value: String){ 37 | a = value 38 | } 39 | 40 | init(){ 41 | a = nil 42 | } 43 | } 44 | 45 | 46 | public protocol EnumListIntRawable{ 47 | init(integerLiteral value: Int) 48 | var value:Int? {get} 49 | } 50 | 51 | public struct EnumListIntRaw: EnumListIntRawable, ExpressibleByIntegerLiteral, Equatable { 52 | public var value: Int?{ 53 | return a 54 | } 55 | 56 | let a:Int? 57 | 58 | public static func ==(lhs: EnumListIntRaw, rhs: EnumListIntRaw) -> Bool { 59 | if let lhsA = lhs.a { T.allRaws.insert(lhsA)} 60 | if let rhsA = rhs.a { T.allRaws.insert(rhsA)} 61 | 62 | return lhs.a == rhs.a 63 | } 64 | public init(integerLiteral value: Int){ 65 | a = value 66 | } 67 | 68 | init(){ 69 | a = nil 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Sources/EnumListRawDecodable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumListRawDecodable.swift 3 | // EnumList 4 | // 5 | // Created by Bartosz Polaczyk on 27/08/2017. 6 | // 7 | 8 | import Foundation 9 | 10 | private extension RawRepresentable{ 11 | /// Throws only when cannot create instance from a given rawValue 12 | /// 13 | /// Required by a limitation of Decoder initalizer that cannot 14 | /// delegate to failable initailizer without implcit unwrap 15 | static func ensureExists(rawValue: RawValue, codingPath: [CodingKey]) throws{ 16 | if self.init(rawValue: rawValue) == nil{ 17 | throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: codingPath, debugDescription: "Invalid value to create \(Self.self) from: \(rawValue)")) 18 | } 19 | } 20 | } 21 | 22 | public extension RawRepresentable where RawValue:EnumListStringRawable{ 23 | init(from decoder: Decoder) throws { 24 | let decoded = try decoder.singleValueContainer().decode(String.self) 25 | let rawValue = RawValue(stringLiteral: decoded) 26 | /// forces intializer to throw an error in case given string does not 27 | /// correspond to any RawRepresentable instance 28 | try Self.ensureExists(rawValue: rawValue, codingPath: decoder.codingPath) 29 | self.init(rawValue: RawValue(stringLiteral: decoded))! 30 | } 31 | } 32 | 33 | public extension RawRepresentable where RawValue:EnumListIntRawable{ 34 | init(from decoder: Decoder) throws { 35 | let decoded = try decoder.singleValueContainer().decode(Int.self) 36 | let rawValue = RawValue(integerLiteral: decoded) 37 | /// forces intializer to throw an error in case given string does not 38 | /// correspond to any RawRepresentable instance 39 | try Self.ensureExists(rawValue: rawValue, codingPath: decoder.codingPath) 40 | self.init(rawValue: rawValue)! 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/EnumListRawEncodable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumListRawEncodable.swift 3 | // EnumList 4 | // 5 | // Created by Bartosz Polaczyk on 27/08/2017. 6 | // 7 | 8 | import Foundation 9 | 10 | public extension RawRepresentable where RawValue:EnumListStringRawable{ 11 | func encode(to encoder: Encoder) throws { 12 | var container = encoder.singleValueContainer() 13 | try container.encode(rawValue.value) 14 | } 15 | } 16 | 17 | public extension RawRepresentable where RawValue:EnumListIntRawable{ 18 | func encode(to encoder: Encoder) throws { 19 | var container = encoder.singleValueContainer() 20 | try container.encode(rawValue.value) 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Sources/EnumValues.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumValues.swift 3 | // Pods 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // 7 | // 8 | 9 | import UIKit 10 | 11 | public protocol EnumValues{ 12 | associatedtype Element:RawRepresentable, Hashable 13 | associatedtype RawType: Hashable 14 | 15 | static var all: Set {get} 16 | static var allRaws:Set {get set} 17 | } 18 | 19 | public protocol StringEnumValues:EnumValues{ 20 | static var allRaws:Set {get set} 21 | } 22 | 23 | public protocol IntEnumValues:EnumValues{ 24 | static var allRaws:Set {get set} 25 | } 26 | -------------------------------------------------------------------------------- /Sources/EnumValuesExtensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumValuesExtensions.swift 3 | // Pods 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // 7 | // 8 | 9 | import UIKit 10 | private extension EnumValues { 11 | static func buildAllElementsSet(conversion:(RawType)->(Element.RawValue)) -> Set{ 12 | let arrayRawValues = allRaws.map(conversion) 13 | return Set(arrayRawValues.flatMap({ 14 | return Element(rawValue: $0) 15 | })) 16 | } 17 | static func resetRaws(imaginationRawValue: Element.RawValue){ 18 | allRaws = [] 19 | _ = Element(rawValue: imaginationRawValue) 20 | } 21 | } 22 | 23 | public extension StringEnumValues where Element.RawValue == EnumListStringRaw, RawType == String{ 24 | static var all: Set { 25 | initialize() 26 | return buildAllElementsSet(conversion:{EnumListStringRaw(stringLiteral: $0)}) 27 | } 28 | static var allRawValues: Set { 29 | initialize() 30 | return allRaws 31 | } 32 | private static func initialize(){ 33 | resetRaws(imaginationRawValue: EnumListStringRaw()) 34 | } 35 | } 36 | 37 | public extension IntEnumValues where Element.RawValue == EnumListIntRaw, RawType == Int{ 38 | static var all: Set { 39 | initialize() 40 | return buildAllElementsSet(conversion:EnumListIntRaw.init) 41 | } 42 | static var allRawValues: Set { 43 | initialize() 44 | return allRaws 45 | } 46 | private static func initialize(){ 47 | resetRaws(imaginationRawValue: EnumListIntRaw()) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Sources/Unbox/EnumList+Unbox.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EnumList+Unbox.swift 3 | // Pods 4 | // 5 | // Created by Bartosz Polaczyk on 12/08/2017. 6 | // 7 | // 8 | 9 | import UIKit 10 | import Unbox 11 | 12 | 13 | 14 | public extension UnboxableEnum where RawValue:ExpressibleByStringLiteral{ 15 | static func unbox(value: Any, allowInvalidCollectionElements: Bool) throws -> Self? { 16 | guard let literal = value as? RawValue.StringLiteralType else { 17 | return nil 18 | } 19 | 20 | return self.init(rawValue: RawValue(stringLiteral: literal)) 21 | } 22 | } 23 | 24 | public extension UnboxableEnum where RawValue:ExpressibleByIntegerLiteral{ 25 | static func unbox(value: Any, allowInvalidCollectionElements: Bool) throws -> Self? { 26 | guard let literal = value as? RawValue.IntegerLiteralType else { 27 | return nil 28 | } 29 | 30 | return self.init(rawValue: RawValue(integerLiteral: literal)) 31 | } 32 | } 33 | --------------------------------------------------------------------------------