├── DiffableDataSource.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── DiffableDataSource ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── Models │ └── Country.swift ├── SceneDelegate.swift ├── Screens │ ├── CollectionView │ │ ├── CollectionViewCell.swift │ │ └── CollectionViewController.swift │ └── TableView │ │ └── TableViewController.swift └── ViewController.swift ├── DiffableDataSourceTests ├── DiffableDataSourceTests.swift └── Info.plist └── LICENSE /DiffableDataSource.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E3A1854822CAF22C00F4D06C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A1854722CAF22C00F4D06C /* AppDelegate.swift */; }; 11 | E3A1854C22CAF22C00F4D06C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A1854B22CAF22C00F4D06C /* ViewController.swift */; }; 12 | E3A1854F22CAF22C00F4D06C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E3A1854D22CAF22C00F4D06C /* Main.storyboard */; }; 13 | E3A1855122CAF22F00F4D06C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E3A1855022CAF22F00F4D06C /* Assets.xcassets */; }; 14 | E3A1855422CAF22F00F4D06C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E3A1855222CAF22F00F4D06C /* LaunchScreen.storyboard */; }; 15 | E3A1855F22CAF22F00F4D06C /* DiffableDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A1855E22CAF22F00F4D06C /* DiffableDataSourceTests.swift */; }; 16 | E3A1856D22CAF35400F4D06C /* CollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A1856C22CAF35400F4D06C /* CollectionViewCell.swift */; }; 17 | E3A1856F22CAF36200F4D06C /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A1856E22CAF36200F4D06C /* TableViewController.swift */; }; 18 | E3A1857122CAF38300F4D06C /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A1857022CAF38300F4D06C /* CollectionViewController.swift */; }; 19 | E3A1857522CAF5BB00F4D06C /* Country.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A1857422CAF5BB00F4D06C /* Country.swift */; }; 20 | E3A1857722CB103500F4D06C /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3A1857622CB103500F4D06C /* SceneDelegate.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | E3A1855B22CAF22F00F4D06C /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = E3A1853C22CAF22C00F4D06C /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = E3A1854322CAF22C00F4D06C; 29 | remoteInfo = DiffableDataSource; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | E3A1854422CAF22C00F4D06C /* DiffableDataSource.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DiffableDataSource.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | E3A1854722CAF22C00F4D06C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 36 | E3A1854B22CAF22C00F4D06C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 37 | E3A1854E22CAF22C00F4D06C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | E3A1855022CAF22F00F4D06C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 39 | E3A1855322CAF22F00F4D06C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 40 | E3A1855522CAF22F00F4D06C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | E3A1855A22CAF22F00F4D06C /* DiffableDataSourceTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DiffableDataSourceTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | E3A1855E22CAF22F00F4D06C /* DiffableDataSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiffableDataSourceTests.swift; sourceTree = ""; }; 43 | E3A1856022CAF22F00F4D06C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | E3A1856C22CAF35400F4D06C /* CollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewCell.swift; sourceTree = ""; }; 45 | E3A1856E22CAF36200F4D06C /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; 46 | E3A1857022CAF38300F4D06C /* CollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewController.swift; sourceTree = ""; }; 47 | E3A1857422CAF5BB00F4D06C /* Country.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Country.swift; sourceTree = ""; }; 48 | E3A1857622CB103500F4D06C /* SceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | E3A1854122CAF22C00F4D06C /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | E3A1855722CAF22F00F4D06C /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | E3A1853B22CAF22C00F4D06C = { 70 | isa = PBXGroup; 71 | children = ( 72 | E3A1854622CAF22C00F4D06C /* DiffableDataSource */, 73 | E3A1855D22CAF22F00F4D06C /* DiffableDataSourceTests */, 74 | E3A1854522CAF22C00F4D06C /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | E3A1854522CAF22C00F4D06C /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | E3A1854422CAF22C00F4D06C /* DiffableDataSource.app */, 82 | E3A1855A22CAF22F00F4D06C /* DiffableDataSourceTests.xctest */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | E3A1854622CAF22C00F4D06C /* DiffableDataSource */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | E3A1857322CAF5B000F4D06C /* Models */, 91 | E3A1856922CAF31F00F4D06C /* Screens */, 92 | E3A1854722CAF22C00F4D06C /* AppDelegate.swift */, 93 | E3A1854B22CAF22C00F4D06C /* ViewController.swift */, 94 | E3A1854D22CAF22C00F4D06C /* Main.storyboard */, 95 | E3A1857622CB103500F4D06C /* SceneDelegate.swift */, 96 | E3A1855022CAF22F00F4D06C /* Assets.xcassets */, 97 | E3A1855222CAF22F00F4D06C /* LaunchScreen.storyboard */, 98 | E3A1855522CAF22F00F4D06C /* Info.plist */, 99 | ); 100 | path = DiffableDataSource; 101 | sourceTree = ""; 102 | }; 103 | E3A1855D22CAF22F00F4D06C /* DiffableDataSourceTests */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | E3A1855E22CAF22F00F4D06C /* DiffableDataSourceTests.swift */, 107 | E3A1856022CAF22F00F4D06C /* Info.plist */, 108 | ); 109 | path = DiffableDataSourceTests; 110 | sourceTree = ""; 111 | }; 112 | E3A1856922CAF31F00F4D06C /* Screens */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | E3A1856B22CAF33100F4D06C /* CollectionView */, 116 | E3A1856A22CAF32700F4D06C /* TableView */, 117 | ); 118 | path = Screens; 119 | sourceTree = ""; 120 | }; 121 | E3A1856A22CAF32700F4D06C /* TableView */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | E3A1856E22CAF36200F4D06C /* TableViewController.swift */, 125 | ); 126 | path = TableView; 127 | sourceTree = ""; 128 | }; 129 | E3A1856B22CAF33100F4D06C /* CollectionView */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | E3A1856C22CAF35400F4D06C /* CollectionViewCell.swift */, 133 | E3A1857022CAF38300F4D06C /* CollectionViewController.swift */, 134 | ); 135 | path = CollectionView; 136 | sourceTree = ""; 137 | }; 138 | E3A1857322CAF5B000F4D06C /* Models */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | E3A1857422CAF5BB00F4D06C /* Country.swift */, 142 | ); 143 | path = Models; 144 | sourceTree = ""; 145 | }; 146 | /* End PBXGroup section */ 147 | 148 | /* Begin PBXNativeTarget section */ 149 | E3A1854322CAF22C00F4D06C /* DiffableDataSource */ = { 150 | isa = PBXNativeTarget; 151 | buildConfigurationList = E3A1856322CAF22F00F4D06C /* Build configuration list for PBXNativeTarget "DiffableDataSource" */; 152 | buildPhases = ( 153 | E3A1854022CAF22C00F4D06C /* Sources */, 154 | E3A1854122CAF22C00F4D06C /* Frameworks */, 155 | E3A1854222CAF22C00F4D06C /* Resources */, 156 | ); 157 | buildRules = ( 158 | ); 159 | dependencies = ( 160 | ); 161 | name = DiffableDataSource; 162 | productName = DiffableDataSource; 163 | productReference = E3A1854422CAF22C00F4D06C /* DiffableDataSource.app */; 164 | productType = "com.apple.product-type.application"; 165 | }; 166 | E3A1855922CAF22F00F4D06C /* DiffableDataSourceTests */ = { 167 | isa = PBXNativeTarget; 168 | buildConfigurationList = E3A1856622CAF22F00F4D06C /* Build configuration list for PBXNativeTarget "DiffableDataSourceTests" */; 169 | buildPhases = ( 170 | E3A1855622CAF22F00F4D06C /* Sources */, 171 | E3A1855722CAF22F00F4D06C /* Frameworks */, 172 | E3A1855822CAF22F00F4D06C /* Resources */, 173 | ); 174 | buildRules = ( 175 | ); 176 | dependencies = ( 177 | E3A1855C22CAF22F00F4D06C /* PBXTargetDependency */, 178 | ); 179 | name = DiffableDataSourceTests; 180 | productName = DiffableDataSourceTests; 181 | productReference = E3A1855A22CAF22F00F4D06C /* DiffableDataSourceTests.xctest */; 182 | productType = "com.apple.product-type.bundle.unit-test"; 183 | }; 184 | /* End PBXNativeTarget section */ 185 | 186 | /* Begin PBXProject section */ 187 | E3A1853C22CAF22C00F4D06C /* Project object */ = { 188 | isa = PBXProject; 189 | attributes = { 190 | LastSwiftUpdateCheck = 1100; 191 | LastUpgradeCheck = 1100; 192 | ORGANIZATIONNAME = "Jayesh Kawli"; 193 | TargetAttributes = { 194 | E3A1854322CAF22C00F4D06C = { 195 | CreatedOnToolsVersion = 11.0; 196 | }; 197 | E3A1855922CAF22F00F4D06C = { 198 | CreatedOnToolsVersion = 11.0; 199 | TestTargetID = E3A1854322CAF22C00F4D06C; 200 | }; 201 | }; 202 | }; 203 | buildConfigurationList = E3A1853F22CAF22C00F4D06C /* Build configuration list for PBXProject "DiffableDataSource" */; 204 | compatibilityVersion = "Xcode 9.3"; 205 | developmentRegion = en; 206 | hasScannedForEncodings = 0; 207 | knownRegions = ( 208 | en, 209 | Base, 210 | ); 211 | mainGroup = E3A1853B22CAF22C00F4D06C; 212 | productRefGroup = E3A1854522CAF22C00F4D06C /* Products */; 213 | projectDirPath = ""; 214 | projectRoot = ""; 215 | targets = ( 216 | E3A1854322CAF22C00F4D06C /* DiffableDataSource */, 217 | E3A1855922CAF22F00F4D06C /* DiffableDataSourceTests */, 218 | ); 219 | }; 220 | /* End PBXProject section */ 221 | 222 | /* Begin PBXResourcesBuildPhase section */ 223 | E3A1854222CAF22C00F4D06C /* Resources */ = { 224 | isa = PBXResourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | E3A1855422CAF22F00F4D06C /* LaunchScreen.storyboard in Resources */, 228 | E3A1855122CAF22F00F4D06C /* Assets.xcassets in Resources */, 229 | E3A1854F22CAF22C00F4D06C /* Main.storyboard in Resources */, 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | E3A1855822CAF22F00F4D06C /* Resources */ = { 234 | isa = PBXResourcesBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | /* End PBXResourcesBuildPhase section */ 241 | 242 | /* Begin PBXSourcesBuildPhase section */ 243 | E3A1854022CAF22C00F4D06C /* Sources */ = { 244 | isa = PBXSourcesBuildPhase; 245 | buildActionMask = 2147483647; 246 | files = ( 247 | E3A1857522CAF5BB00F4D06C /* Country.swift in Sources */, 248 | E3A1857722CB103500F4D06C /* SceneDelegate.swift in Sources */, 249 | E3A1857122CAF38300F4D06C /* CollectionViewController.swift in Sources */, 250 | E3A1854C22CAF22C00F4D06C /* ViewController.swift in Sources */, 251 | E3A1856D22CAF35400F4D06C /* CollectionViewCell.swift in Sources */, 252 | E3A1854822CAF22C00F4D06C /* AppDelegate.swift in Sources */, 253 | E3A1856F22CAF36200F4D06C /* TableViewController.swift in Sources */, 254 | ); 255 | runOnlyForDeploymentPostprocessing = 0; 256 | }; 257 | E3A1855622CAF22F00F4D06C /* Sources */ = { 258 | isa = PBXSourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | E3A1855F22CAF22F00F4D06C /* DiffableDataSourceTests.swift in Sources */, 262 | ); 263 | runOnlyForDeploymentPostprocessing = 0; 264 | }; 265 | /* End PBXSourcesBuildPhase section */ 266 | 267 | /* Begin PBXTargetDependency section */ 268 | E3A1855C22CAF22F00F4D06C /* PBXTargetDependency */ = { 269 | isa = PBXTargetDependency; 270 | target = E3A1854322CAF22C00F4D06C /* DiffableDataSource */; 271 | targetProxy = E3A1855B22CAF22F00F4D06C /* PBXContainerItemProxy */; 272 | }; 273 | /* End PBXTargetDependency section */ 274 | 275 | /* Begin PBXVariantGroup section */ 276 | E3A1854D22CAF22C00F4D06C /* Main.storyboard */ = { 277 | isa = PBXVariantGroup; 278 | children = ( 279 | E3A1854E22CAF22C00F4D06C /* Base */, 280 | ); 281 | name = Main.storyboard; 282 | sourceTree = ""; 283 | }; 284 | E3A1855222CAF22F00F4D06C /* LaunchScreen.storyboard */ = { 285 | isa = PBXVariantGroup; 286 | children = ( 287 | E3A1855322CAF22F00F4D06C /* Base */, 288 | ); 289 | name = LaunchScreen.storyboard; 290 | sourceTree = ""; 291 | }; 292 | /* End PBXVariantGroup section */ 293 | 294 | /* Begin XCBuildConfiguration section */ 295 | E3A1856122CAF22F00F4D06C /* Debug */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ALWAYS_SEARCH_USER_PATHS = NO; 299 | CLANG_ANALYZER_NONNULL = YES; 300 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 301 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 302 | CLANG_CXX_LIBRARY = "libc++"; 303 | CLANG_ENABLE_MODULES = YES; 304 | CLANG_ENABLE_OBJC_ARC = YES; 305 | CLANG_ENABLE_OBJC_WEAK = YES; 306 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 307 | CLANG_WARN_BOOL_CONVERSION = YES; 308 | CLANG_WARN_COMMA = YES; 309 | CLANG_WARN_CONSTANT_CONVERSION = YES; 310 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 311 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 312 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 313 | CLANG_WARN_EMPTY_BODY = YES; 314 | CLANG_WARN_ENUM_CONVERSION = YES; 315 | CLANG_WARN_INFINITE_RECURSION = YES; 316 | CLANG_WARN_INT_CONVERSION = YES; 317 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 318 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 319 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 320 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 321 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 322 | CLANG_WARN_STRICT_PROTOTYPES = YES; 323 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 324 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 325 | CLANG_WARN_UNREACHABLE_CODE = YES; 326 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 327 | COPY_PHASE_STRIP = NO; 328 | DEBUG_INFORMATION_FORMAT = dwarf; 329 | ENABLE_STRICT_OBJC_MSGSEND = YES; 330 | ENABLE_TESTABILITY = YES; 331 | GCC_C_LANGUAGE_STANDARD = gnu11; 332 | GCC_DYNAMIC_NO_PIC = NO; 333 | GCC_NO_COMMON_BLOCKS = YES; 334 | GCC_OPTIMIZATION_LEVEL = 0; 335 | GCC_PREPROCESSOR_DEFINITIONS = ( 336 | "DEBUG=1", 337 | "$(inherited)", 338 | ); 339 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 340 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 341 | GCC_WARN_UNDECLARED_SELECTOR = YES; 342 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 343 | GCC_WARN_UNUSED_FUNCTION = YES; 344 | GCC_WARN_UNUSED_VARIABLE = YES; 345 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 346 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 347 | MTL_FAST_MATH = YES; 348 | ONLY_ACTIVE_ARCH = YES; 349 | SDKROOT = iphoneos; 350 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 351 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 352 | }; 353 | name = Debug; 354 | }; 355 | E3A1856222CAF22F00F4D06C /* Release */ = { 356 | isa = XCBuildConfiguration; 357 | buildSettings = { 358 | ALWAYS_SEARCH_USER_PATHS = NO; 359 | CLANG_ANALYZER_NONNULL = YES; 360 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 361 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 362 | CLANG_CXX_LIBRARY = "libc++"; 363 | CLANG_ENABLE_MODULES = YES; 364 | CLANG_ENABLE_OBJC_ARC = YES; 365 | CLANG_ENABLE_OBJC_WEAK = YES; 366 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 367 | CLANG_WARN_BOOL_CONVERSION = YES; 368 | CLANG_WARN_COMMA = YES; 369 | CLANG_WARN_CONSTANT_CONVERSION = YES; 370 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 371 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 372 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 373 | CLANG_WARN_EMPTY_BODY = YES; 374 | CLANG_WARN_ENUM_CONVERSION = YES; 375 | CLANG_WARN_INFINITE_RECURSION = YES; 376 | CLANG_WARN_INT_CONVERSION = YES; 377 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 378 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 379 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 380 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 381 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 382 | CLANG_WARN_STRICT_PROTOTYPES = YES; 383 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 384 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 385 | CLANG_WARN_UNREACHABLE_CODE = YES; 386 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 387 | COPY_PHASE_STRIP = NO; 388 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 389 | ENABLE_NS_ASSERTIONS = NO; 390 | ENABLE_STRICT_OBJC_MSGSEND = YES; 391 | GCC_C_LANGUAGE_STANDARD = gnu11; 392 | GCC_NO_COMMON_BLOCKS = YES; 393 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 394 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 395 | GCC_WARN_UNDECLARED_SELECTOR = YES; 396 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 397 | GCC_WARN_UNUSED_FUNCTION = YES; 398 | GCC_WARN_UNUSED_VARIABLE = YES; 399 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 400 | MTL_ENABLE_DEBUG_INFO = NO; 401 | MTL_FAST_MATH = YES; 402 | SDKROOT = iphoneos; 403 | SWIFT_COMPILATION_MODE = wholemodule; 404 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 405 | VALIDATE_PRODUCT = YES; 406 | }; 407 | name = Release; 408 | }; 409 | E3A1856422CAF22F00F4D06C /* Debug */ = { 410 | isa = XCBuildConfiguration; 411 | buildSettings = { 412 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 413 | CODE_SIGN_STYLE = Automatic; 414 | INFOPLIST_FILE = DiffableDataSource/Info.plist; 415 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 416 | LD_RUNPATH_SEARCH_PATHS = ( 417 | "$(inherited)", 418 | "@executable_path/Frameworks", 419 | ); 420 | PRODUCT_BUNDLE_IDENTIFIER = WF.DiffableDataSource; 421 | PRODUCT_NAME = "$(TARGET_NAME)"; 422 | SWIFT_VERSION = 5.0; 423 | TARGETED_DEVICE_FAMILY = "1,2"; 424 | }; 425 | name = Debug; 426 | }; 427 | E3A1856522CAF22F00F4D06C /* Release */ = { 428 | isa = XCBuildConfiguration; 429 | buildSettings = { 430 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 431 | CODE_SIGN_STYLE = Automatic; 432 | INFOPLIST_FILE = DiffableDataSource/Info.plist; 433 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 434 | LD_RUNPATH_SEARCH_PATHS = ( 435 | "$(inherited)", 436 | "@executable_path/Frameworks", 437 | ); 438 | PRODUCT_BUNDLE_IDENTIFIER = WF.DiffableDataSource; 439 | PRODUCT_NAME = "$(TARGET_NAME)"; 440 | SWIFT_VERSION = 5.0; 441 | TARGETED_DEVICE_FAMILY = "1,2"; 442 | }; 443 | name = Release; 444 | }; 445 | E3A1856722CAF22F00F4D06C /* Debug */ = { 446 | isa = XCBuildConfiguration; 447 | buildSettings = { 448 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 449 | BUNDLE_LOADER = "$(TEST_HOST)"; 450 | CODE_SIGN_STYLE = Automatic; 451 | INFOPLIST_FILE = DiffableDataSourceTests/Info.plist; 452 | LD_RUNPATH_SEARCH_PATHS = ( 453 | "$(inherited)", 454 | "@executable_path/Frameworks", 455 | "@loader_path/Frameworks", 456 | ); 457 | PRODUCT_BUNDLE_IDENTIFIER = WF.DiffableDataSourceTests; 458 | PRODUCT_NAME = "$(TARGET_NAME)"; 459 | SWIFT_VERSION = 5.0; 460 | TARGETED_DEVICE_FAMILY = "1,2"; 461 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DiffableDataSource.app/DiffableDataSource"; 462 | }; 463 | name = Debug; 464 | }; 465 | E3A1856822CAF22F00F4D06C /* Release */ = { 466 | isa = XCBuildConfiguration; 467 | buildSettings = { 468 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 469 | BUNDLE_LOADER = "$(TEST_HOST)"; 470 | CODE_SIGN_STYLE = Automatic; 471 | INFOPLIST_FILE = DiffableDataSourceTests/Info.plist; 472 | LD_RUNPATH_SEARCH_PATHS = ( 473 | "$(inherited)", 474 | "@executable_path/Frameworks", 475 | "@loader_path/Frameworks", 476 | ); 477 | PRODUCT_BUNDLE_IDENTIFIER = WF.DiffableDataSourceTests; 478 | PRODUCT_NAME = "$(TARGET_NAME)"; 479 | SWIFT_VERSION = 5.0; 480 | TARGETED_DEVICE_FAMILY = "1,2"; 481 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DiffableDataSource.app/DiffableDataSource"; 482 | }; 483 | name = Release; 484 | }; 485 | /* End XCBuildConfiguration section */ 486 | 487 | /* Begin XCConfigurationList section */ 488 | E3A1853F22CAF22C00F4D06C /* Build configuration list for PBXProject "DiffableDataSource" */ = { 489 | isa = XCConfigurationList; 490 | buildConfigurations = ( 491 | E3A1856122CAF22F00F4D06C /* Debug */, 492 | E3A1856222CAF22F00F4D06C /* Release */, 493 | ); 494 | defaultConfigurationIsVisible = 0; 495 | defaultConfigurationName = Release; 496 | }; 497 | E3A1856322CAF22F00F4D06C /* Build configuration list for PBXNativeTarget "DiffableDataSource" */ = { 498 | isa = XCConfigurationList; 499 | buildConfigurations = ( 500 | E3A1856422CAF22F00F4D06C /* Debug */, 501 | E3A1856522CAF22F00F4D06C /* Release */, 502 | ); 503 | defaultConfigurationIsVisible = 0; 504 | defaultConfigurationName = Release; 505 | }; 506 | E3A1856622CAF22F00F4D06C /* Build configuration list for PBXNativeTarget "DiffableDataSourceTests" */ = { 507 | isa = XCConfigurationList; 508 | buildConfigurations = ( 509 | E3A1856722CAF22F00F4D06C /* Debug */, 510 | E3A1856822CAF22F00F4D06C /* Release */, 511 | ); 512 | defaultConfigurationIsVisible = 0; 513 | defaultConfigurationName = Release; 514 | }; 515 | /* End XCConfigurationList section */ 516 | }; 517 | rootObject = E3A1853C22CAF22C00F4D06C /* Project object */; 518 | } 519 | -------------------------------------------------------------------------------- /DiffableDataSource.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DiffableDataSource.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DiffableDataSource/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DiffableDataSource 4 | // 5 | // Created by Jayesh Kawli on 7/1/19. 6 | // Copyright © 2019 Jayesh Kawli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | func applicationWillTerminate(_ application: UIApplication) { 22 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 23 | } 24 | 25 | // MARK: UISceneSession Lifecycle 26 | 27 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 28 | // Called when a new scene session is being created. 29 | // Use this method to select a configuration to create the new scene with. 30 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 31 | } 32 | 33 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 34 | // Called when the user discards a scene session. 35 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 36 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 37 | } 38 | 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /DiffableDataSource/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /DiffableDataSource/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DiffableDataSource/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 | -------------------------------------------------------------------------------- /DiffableDataSource/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 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 43 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 157 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /DiffableDataSource/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UILaunchStoryboardName 33 | LaunchScreen 34 | UISceneConfigurationName 35 | Default Configuration 36 | UISceneDelegateClassName 37 | $(PRODUCT_MODULE_NAME).SceneDelegate 38 | UISceneStoryboardFile 39 | Main 40 | 41 | 42 | 43 | 44 | UILaunchStoryboardName 45 | LaunchScreen 46 | UIMainStoryboardFile 47 | Main 48 | UIRequiredDeviceCapabilities 49 | 50 | armv7 51 | 52 | UISupportedInterfaceOrientations 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationLandscapeLeft 56 | UIInterfaceOrientationLandscapeRight 57 | 58 | UISupportedInterfaceOrientations~ipad 59 | 60 | UIInterfaceOrientationPortrait 61 | UIInterfaceOrientationPortraitUpsideDown 62 | UIInterfaceOrientationLandscapeLeft 63 | UIInterfaceOrientationLandscapeRight 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /DiffableDataSource/Models/Country.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Country.swift 3 | // DiffableDataSource 4 | // 5 | // Created by Jayesh Kawli on 7/1/19. 6 | // Copyright © 2019 Jayesh Kawli. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Country: Hashable { 12 | let name: String 13 | let identifier = UUID() 14 | 15 | func hash(into hasher: inout Hasher) { 16 | hasher.combine(identifier) 17 | } 18 | 19 | static func ==(lhs: Country, rhs: Country) -> Bool { 20 | return lhs.identifier == rhs.identifier 21 | } 22 | 23 | func contains(query: String?) -> Bool { 24 | guard let query = query else { return true } 25 | guard !query.isEmpty else { return true } 26 | let lowerCasedQuery = query.lowercased() 27 | return name.lowercased().contains(lowerCasedQuery) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DiffableDataSource/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // DiffableDataSource 4 | // 5 | // Created by Jayesh Kawli on 7/1/19. 6 | // Copyright © 2019 Jayesh Kawli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | 16 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 17 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 18 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 19 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 20 | guard let _ = (scene as? UIWindowScene) else { return } 21 | } 22 | 23 | func sceneDidDisconnect(_ scene: UIScene) { 24 | // Called as the scene is being released by the system. 25 | // This occurs shortly after the scene enters the background, or when its session is discarded. 26 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 27 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 28 | } 29 | 30 | func sceneDidBecomeActive(_ scene: UIScene) { 31 | // Called when the scene has moved from an inactive state to an active state. 32 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 33 | } 34 | 35 | func sceneWillResignActive(_ scene: UIScene) { 36 | // Called when the scene will move from an active state to an inactive state. 37 | // This may occur due to temporary interruptions (ex. an incoming phone call). 38 | } 39 | 40 | func sceneWillEnterForeground(_ scene: UIScene) { 41 | // Called as the scene transitions from the background to the foreground. 42 | // Use this method to undo the changes made on entering the background. 43 | } 44 | 45 | func sceneDidEnterBackground(_ scene: UIScene) { 46 | // Called as the scene transitions from the foreground to the background. 47 | // Use this method to save data, release shared resources, and store enough scene-specific state information 48 | // to restore the scene back to its current state. 49 | } 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /DiffableDataSource/Screens/CollectionView/CollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewCell.swift 3 | // DiffableDataSource 4 | // 5 | // Created by Jayesh Kawli on 7/1/19. 6 | // Copyright © 2019 Jayesh Kawli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MyCellCollectionViewCell: UICollectionViewCell { 12 | 13 | @IBOutlet weak var headerLabel: UILabel! 14 | @IBOutlet weak var descriptionLabel: UILabel! 15 | @IBOutlet weak var widthConstraint: NSLayoutConstraint! 16 | @IBOutlet weak var customBackgroundView: UIView! 17 | 18 | override func awakeFromNib() { 19 | self.contentView.translatesAutoresizingMaskIntoConstraints = false 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DiffableDataSource/Screens/CollectionView/CollectionViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CollectionViewController.swift 3 | // DiffableDataSource 4 | // 5 | // Created by Jayesh Kawli on 7/1/19. 6 | // Copyright © 2019 Jayesh Kawli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class CollectionViewController: UIViewController { 12 | 13 | enum Section: CaseIterable { 14 | case main 15 | } 16 | 17 | @IBOutlet weak var collectionView: UICollectionView! 18 | var dataSource: UICollectionViewDiffableDataSource! 19 | var countries: [Country] = [] 20 | 21 | override func viewDidLoad() { 22 | super.viewDidLoad() 23 | 24 | let countryNames = ["Afghanistan", 25 | "Albania", 26 | "Algeria", 27 | "Andorra", 28 | "Angola", 29 | "Antigua and Barbuda and or and or", 30 | "Argentina", 31 | "Armenia", 32 | "Australia", 33 | "Austria", 34 | "Azerbaijan", 35 | "Bahamas", 36 | "Bahrain", 37 | "Bangladesh", 38 | "Barbados", 39 | "Belarus"] 40 | for name in countryNames { 41 | countries.append(Country(name: name)) 42 | } 43 | 44 | dataSource = UICollectionViewDiffableDataSource 45 | (collectionView: collectionView) { 46 | (collectionView: UICollectionView, indexPath: IndexPath, 47 | country: Country) -> UICollectionViewCell? in 48 | guard let cell = collectionView.dequeueReusableCell( 49 | withReuseIdentifier: "cell", for: indexPath) as? MyCellCollectionViewCell else { 50 | fatalError("Cannot create new cell") } 51 | cell.headerLabel.text = "Country" 52 | cell.descriptionLabel.text = country.name 53 | let screenWidth = collectionView.frame.size.width 54 | cell.widthConstraint.constant = (screenWidth/2.0) - (2 * 16.0) 55 | return cell 56 | } 57 | 58 | if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout { 59 | flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize 60 | } 61 | } 62 | 63 | override func viewDidLayoutSubviews() { 64 | super.viewDidLayoutSubviews() 65 | performSearch(searchQuery: nil) 66 | } 67 | 68 | func performSearch(searchQuery: String?) { 69 | let filteredCountries: [Country] 70 | if let searchQuery = searchQuery, !searchQuery.isEmpty { 71 | filteredCountries = countries.filter { $0.contains(query: searchQuery) } 72 | } else { 73 | filteredCountries = countries 74 | } 75 | let snapshot = NSDiffableDataSourceSnapshot() 76 | snapshot.appendSections([.main]) 77 | snapshot.appendItems(filteredCountries, toSection: .main) 78 | dataSource.apply(snapshot, animatingDifferences: true) 79 | } 80 | } 81 | 82 | extension CollectionViewController: UISearchBarDelegate { 83 | func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { 84 | performSearch(searchQuery: searchText) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DiffableDataSource/Screens/TableView/TableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.swift 3 | // DiffableDataSource 4 | // 5 | // Created by Jayesh Kawli on 7/1/19. 6 | // Copyright © 2019 Jayesh Kawli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class TableViewController: UIViewController { 12 | 13 | enum Section: CaseIterable { 14 | case main 15 | } 16 | 17 | @IBOutlet weak var tableView: UITableView! 18 | var countries: [Country] = [] 19 | var dataSource: UITableViewDiffableDataSource! 20 | 21 | override func viewDidLoad() { 22 | super.viewDidLoad() 23 | 24 | let countryNames = ["Afghanistan", 25 | "Albania", 26 | "Algeria", 27 | "Andorra", 28 | "Angola", 29 | "Antigua and Barbuda", 30 | "Argentina", 31 | "Armenia", 32 | "Australia", 33 | "Austria", 34 | "Azerbaijan", 35 | "Bahamas", 36 | "Bahrain", 37 | "Bangladesh", 38 | "Barbados", 39 | "Belarus"] 40 | for name in countryNames { 41 | countries.append(Country(name: name)) 42 | } 43 | 44 | dataSource = UITableViewDiffableDataSource 45 | (tableView: tableView) { 46 | (tableView: UITableView, indexPath: IndexPath, 47 | country: Country) -> UITableViewCell? in 48 | let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 49 | cell.textLabel?.text = country.name 50 | return cell 51 | } 52 | dataSource.defaultRowAnimation = .fade 53 | } 54 | 55 | override func viewDidLayoutSubviews() { 56 | super.viewDidLayoutSubviews() 57 | performSearch(searchQuery: nil) 58 | } 59 | 60 | func performSearch(searchQuery: String?) { 61 | let filteredCountries: [Country] 62 | if let searchQuery = searchQuery, !searchQuery.isEmpty { 63 | filteredCountries = countries.filter { $0.contains(query: searchQuery) } 64 | } else { 65 | filteredCountries = countries 66 | } 67 | let snapshot = NSDiffableDataSourceSnapshot() 68 | snapshot.appendSections([.main]) 69 | snapshot.appendItems(filteredCountries, toSection: .main) 70 | dataSource.apply(snapshot, animatingDifferences: true) 71 | } 72 | } 73 | 74 | extension TableViewController: UISearchBarDelegate { 75 | func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { 76 | performSearch(searchQuery: searchText) 77 | } 78 | } 79 | 80 | extension TableViewController: UITableViewDelegate { 81 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 82 | if let country = dataSource.itemIdentifier(for: indexPath) { 83 | print("Selected country \(country.name)") 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DiffableDataSource/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // DiffableDataSource 4 | // 5 | // Created by Jayesh Kawli on 7/1/19. 6 | // Copyright © 2019 Jayesh Kawli. 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. 16 | } 17 | 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /DiffableDataSourceTests/DiffableDataSourceTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DiffableDataSourceTests.swift 3 | // DiffableDataSourceTests 4 | // 5 | // Created by Jayesh Kawli on 7/1/19. 6 | // Copyright © 2019 Jayesh Kawli. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import DiffableDataSource 11 | 12 | class DiffableDataSourceTests: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func testExample() { 23 | // This is an example of a functional test case. 24 | // Use XCTAssert and related functions to verify your tests produce the correct results. 25 | } 26 | 27 | func testPerformanceExample() { 28 | // This is an example of a performance test case. 29 | self.measure { 30 | // Put the code you want to measure the time of here. 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /DiffableDataSourceTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jayesh Kawli 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 | --------------------------------------------------------------------------------