├── .gitignore ├── ArrayDiff.podspec ├── ArrayDiff.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── ArrayDiff.xcscheme ├── ArrayDiff ├── ArrayDiff.h ├── ArrayDiff.swift ├── FoundationExtensions.swift ├── Info.plist ├── Section.swift └── UIKitIntegration.swift ├── ArrayDiffTests ├── ArrayDiffTests.swift └── Info.plist ├── Example ├── ArrayDiffExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── ArrayDiffExample.xcworkspace │ └── contents.xcworkspacedata ├── ArrayDiffExample │ ├── AppDelegate.swift │ ├── ArrayDiffExample-Bridging-Header.h │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── Utilities.swift │ └── ViewController.swift └── Podfile ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | Example/Podfile.lock 21 | 22 | # CocoaPods 23 | # 24 | # We recommend against adding the Pods directory to your .gitignore. However 25 | # you should judge for yourself, the pros and cons are mentioned at: 26 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 27 | # 28 | Pods/ 29 | 30 | # Carthage 31 | # 32 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 33 | # Carthage/Checkouts 34 | 35 | Carthage/Build 36 | -------------------------------------------------------------------------------- /ArrayDiff.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | s.name = "ArrayDiff" 4 | s.version = "1.3.0" 5 | s.summary = "ArrayDiff quickly computes the difference between two arrays, works great with UITableView/UICollectionView" 6 | s.homepage = "https://github.com/Adlai-Holler/ArrayDiff" 7 | s.license = { :type => "MIT" } 8 | s.authors = { "Adlai-Holler" => "adlai@icloud.com" } 9 | 10 | s.requires_arc = true 11 | s.ios.deployment_target = "8.0" 12 | s.source = { :git => "https://github.com/Adlai-Holler/ArrayDiff.git", :tag => "v#{s.version}" } 13 | s.source_files = "ArrayDiff/*.swift" 14 | end 15 | -------------------------------------------------------------------------------- /ArrayDiff.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CC642FB41BC056510024AD39 /* Section.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC642FB31BC056510024AD39 /* Section.swift */; }; 11 | CC642FB61BC0596A0024AD39 /* UIKitIntegration.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC642FB51BC0596A0024AD39 /* UIKitIntegration.swift */; }; 12 | CC71C1571BBDD4B400772EDB /* ArrayDiff.h in Headers */ = {isa = PBXBuildFile; fileRef = CC71C1561BBDD4B400772EDB /* ArrayDiff.h */; settings = {ATTRIBUTES = (Public, ); }; }; 13 | CC71C15E1BBDD4B500772EDB /* ArrayDiff.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC71C1531BBDD4B400772EDB /* ArrayDiff.framework */; }; 14 | CC71C1631BBDD4B500772EDB /* ArrayDiffTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC71C1621BBDD4B500772EDB /* ArrayDiffTests.swift */; }; 15 | CC71C16E1BBDD4C000772EDB /* ArrayDiff.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC71C16D1BBDD4C000772EDB /* ArrayDiff.swift */; }; 16 | CC71C1701BBDDBEC00772EDB /* FoundationExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC71C16F1BBDDBEC00772EDB /* FoundationExtensions.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | CC71C15F1BBDD4B500772EDB /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = CC71C14A1BBDD4B400772EDB /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = CC71C1521BBDD4B400772EDB; 25 | remoteInfo = ArrayDiff; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | CC642FB31BC056510024AD39 /* Section.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Section.swift; sourceTree = ""; }; 31 | CC642FB51BC0596A0024AD39 /* UIKitIntegration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIKitIntegration.swift; sourceTree = ""; }; 32 | CC71C1531BBDD4B400772EDB /* ArrayDiff.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ArrayDiff.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | CC71C1561BBDD4B400772EDB /* ArrayDiff.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ArrayDiff.h; sourceTree = ""; }; 34 | CC71C1581BBDD4B400772EDB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | CC71C15D1BBDD4B500772EDB /* ArrayDiffTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ArrayDiffTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | CC71C1621BBDD4B500772EDB /* ArrayDiffTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayDiffTests.swift; sourceTree = ""; }; 37 | CC71C1641BBDD4B500772EDB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | CC71C16D1BBDD4C000772EDB /* ArrayDiff.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayDiff.swift; sourceTree = ""; }; 39 | CC71C16F1BBDDBEC00772EDB /* FoundationExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationExtensions.swift; sourceTree = ""; }; 40 | /* End PBXFileReference section */ 41 | 42 | /* Begin PBXFrameworksBuildPhase section */ 43 | CC71C14F1BBDD4B400772EDB /* Frameworks */ = { 44 | isa = PBXFrameworksBuildPhase; 45 | buildActionMask = 2147483647; 46 | files = ( 47 | ); 48 | runOnlyForDeploymentPostprocessing = 0; 49 | }; 50 | CC71C15A1BBDD4B500772EDB /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | CC71C15E1BBDD4B500772EDB /* ArrayDiff.framework in Frameworks */, 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | /* End PBXFrameworksBuildPhase section */ 59 | 60 | /* Begin PBXGroup section */ 61 | CC71C1491BBDD4B400772EDB = { 62 | isa = PBXGroup; 63 | children = ( 64 | CC71C1551BBDD4B400772EDB /* ArrayDiff */, 65 | CC71C1611BBDD4B500772EDB /* ArrayDiffTests */, 66 | CC71C1541BBDD4B400772EDB /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | CC71C1541BBDD4B400772EDB /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | CC71C1531BBDD4B400772EDB /* ArrayDiff.framework */, 74 | CC71C15D1BBDD4B500772EDB /* ArrayDiffTests.xctest */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | CC71C1551BBDD4B400772EDB /* ArrayDiff */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | CC71C1561BBDD4B400772EDB /* ArrayDiff.h */, 83 | CC71C16F1BBDDBEC00772EDB /* FoundationExtensions.swift */, 84 | CC71C16D1BBDD4C000772EDB /* ArrayDiff.swift */, 85 | CC642FB31BC056510024AD39 /* Section.swift */, 86 | CC642FB51BC0596A0024AD39 /* UIKitIntegration.swift */, 87 | CC71C1581BBDD4B400772EDB /* Info.plist */, 88 | ); 89 | path = ArrayDiff; 90 | sourceTree = ""; 91 | }; 92 | CC71C1611BBDD4B500772EDB /* ArrayDiffTests */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | CC71C1621BBDD4B500772EDB /* ArrayDiffTests.swift */, 96 | CC71C1641BBDD4B500772EDB /* Info.plist */, 97 | ); 98 | path = ArrayDiffTests; 99 | sourceTree = ""; 100 | }; 101 | /* End PBXGroup section */ 102 | 103 | /* Begin PBXHeadersBuildPhase section */ 104 | CC71C1501BBDD4B400772EDB /* Headers */ = { 105 | isa = PBXHeadersBuildPhase; 106 | buildActionMask = 2147483647; 107 | files = ( 108 | CC71C1571BBDD4B400772EDB /* ArrayDiff.h in Headers */, 109 | ); 110 | runOnlyForDeploymentPostprocessing = 0; 111 | }; 112 | /* End PBXHeadersBuildPhase section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | CC71C1521BBDD4B400772EDB /* ArrayDiff */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = CC71C1671BBDD4B500772EDB /* Build configuration list for PBXNativeTarget "ArrayDiff" */; 118 | buildPhases = ( 119 | CC71C14E1BBDD4B400772EDB /* Sources */, 120 | CC71C14F1BBDD4B400772EDB /* Frameworks */, 121 | CC71C1501BBDD4B400772EDB /* Headers */, 122 | CC71C1511BBDD4B400772EDB /* Resources */, 123 | ); 124 | buildRules = ( 125 | ); 126 | dependencies = ( 127 | ); 128 | name = ArrayDiff; 129 | productName = ArrayDiff; 130 | productReference = CC71C1531BBDD4B400772EDB /* ArrayDiff.framework */; 131 | productType = "com.apple.product-type.framework"; 132 | }; 133 | CC71C15C1BBDD4B500772EDB /* ArrayDiffTests */ = { 134 | isa = PBXNativeTarget; 135 | buildConfigurationList = CC71C16A1BBDD4B500772EDB /* Build configuration list for PBXNativeTarget "ArrayDiffTests" */; 136 | buildPhases = ( 137 | CC71C1591BBDD4B500772EDB /* Sources */, 138 | CC71C15A1BBDD4B500772EDB /* Frameworks */, 139 | CC71C15B1BBDD4B500772EDB /* Resources */, 140 | ); 141 | buildRules = ( 142 | ); 143 | dependencies = ( 144 | CC71C1601BBDD4B500772EDB /* PBXTargetDependency */, 145 | ); 146 | name = ArrayDiffTests; 147 | productName = ArrayDiffTests; 148 | productReference = CC71C15D1BBDD4B500772EDB /* ArrayDiffTests.xctest */; 149 | productType = "com.apple.product-type.bundle.unit-test"; 150 | }; 151 | /* End PBXNativeTarget section */ 152 | 153 | /* Begin PBXProject section */ 154 | CC71C14A1BBDD4B400772EDB /* Project object */ = { 155 | isa = PBXProject; 156 | attributes = { 157 | LastSwiftUpdateCheck = 0700; 158 | LastUpgradeCheck = 0700; 159 | ORGANIZATIONNAME = "Adlai Holler"; 160 | TargetAttributes = { 161 | CC71C1521BBDD4B400772EDB = { 162 | CreatedOnToolsVersion = 7.0.1; 163 | }; 164 | CC71C15C1BBDD4B500772EDB = { 165 | CreatedOnToolsVersion = 7.0.1; 166 | }; 167 | }; 168 | }; 169 | buildConfigurationList = CC71C14D1BBDD4B400772EDB /* Build configuration list for PBXProject "ArrayDiff" */; 170 | compatibilityVersion = "Xcode 3.2"; 171 | developmentRegion = English; 172 | hasScannedForEncodings = 0; 173 | knownRegions = ( 174 | en, 175 | ); 176 | mainGroup = CC71C1491BBDD4B400772EDB; 177 | productRefGroup = CC71C1541BBDD4B400772EDB /* Products */; 178 | projectDirPath = ""; 179 | projectRoot = ""; 180 | targets = ( 181 | CC71C1521BBDD4B400772EDB /* ArrayDiff */, 182 | CC71C15C1BBDD4B500772EDB /* ArrayDiffTests */, 183 | ); 184 | }; 185 | /* End PBXProject section */ 186 | 187 | /* Begin PBXResourcesBuildPhase section */ 188 | CC71C1511BBDD4B400772EDB /* Resources */ = { 189 | isa = PBXResourcesBuildPhase; 190 | buildActionMask = 2147483647; 191 | files = ( 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | CC71C15B1BBDD4B500772EDB /* Resources */ = { 196 | isa = PBXResourcesBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | }; 202 | /* End PBXResourcesBuildPhase section */ 203 | 204 | /* Begin PBXSourcesBuildPhase section */ 205 | CC71C14E1BBDD4B400772EDB /* Sources */ = { 206 | isa = PBXSourcesBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | CC642FB41BC056510024AD39 /* Section.swift in Sources */, 210 | CC71C1701BBDDBEC00772EDB /* FoundationExtensions.swift in Sources */, 211 | CC71C16E1BBDD4C000772EDB /* ArrayDiff.swift in Sources */, 212 | CC642FB61BC0596A0024AD39 /* UIKitIntegration.swift in Sources */, 213 | ); 214 | runOnlyForDeploymentPostprocessing = 0; 215 | }; 216 | CC71C1591BBDD4B500772EDB /* Sources */ = { 217 | isa = PBXSourcesBuildPhase; 218 | buildActionMask = 2147483647; 219 | files = ( 220 | CC71C1631BBDD4B500772EDB /* ArrayDiffTests.swift in Sources */, 221 | ); 222 | runOnlyForDeploymentPostprocessing = 0; 223 | }; 224 | /* End PBXSourcesBuildPhase section */ 225 | 226 | /* Begin PBXTargetDependency section */ 227 | CC71C1601BBDD4B500772EDB /* PBXTargetDependency */ = { 228 | isa = PBXTargetDependency; 229 | target = CC71C1521BBDD4B400772EDB /* ArrayDiff */; 230 | targetProxy = CC71C15F1BBDD4B500772EDB /* PBXContainerItemProxy */; 231 | }; 232 | /* End PBXTargetDependency section */ 233 | 234 | /* Begin XCBuildConfiguration section */ 235 | CC71C1651BBDD4B500772EDB /* Debug */ = { 236 | isa = XCBuildConfiguration; 237 | buildSettings = { 238 | ALWAYS_SEARCH_USER_PATHS = NO; 239 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 240 | CLANG_CXX_LIBRARY = "libc++"; 241 | CLANG_ENABLE_MODULES = YES; 242 | CLANG_ENABLE_OBJC_ARC = YES; 243 | CLANG_WARN_BOOL_CONVERSION = YES; 244 | CLANG_WARN_CONSTANT_CONVERSION = YES; 245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 246 | CLANG_WARN_EMPTY_BODY = YES; 247 | CLANG_WARN_ENUM_CONVERSION = YES; 248 | CLANG_WARN_INT_CONVERSION = YES; 249 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 250 | CLANG_WARN_UNREACHABLE_CODE = YES; 251 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 252 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 253 | COPY_PHASE_STRIP = NO; 254 | CURRENT_PROJECT_VERSION = 1; 255 | DEBUG_INFORMATION_FORMAT = dwarf; 256 | ENABLE_STRICT_OBJC_MSGSEND = YES; 257 | ENABLE_TESTABILITY = YES; 258 | GCC_C_LANGUAGE_STANDARD = gnu99; 259 | GCC_DYNAMIC_NO_PIC = NO; 260 | GCC_NO_COMMON_BLOCKS = YES; 261 | GCC_OPTIMIZATION_LEVEL = 0; 262 | GCC_PREPROCESSOR_DEFINITIONS = ( 263 | "DEBUG=1", 264 | "$(inherited)", 265 | ); 266 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 267 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 268 | GCC_WARN_UNDECLARED_SELECTOR = YES; 269 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 270 | GCC_WARN_UNUSED_FUNCTION = YES; 271 | GCC_WARN_UNUSED_VARIABLE = YES; 272 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 273 | MTL_ENABLE_DEBUG_INFO = YES; 274 | ONLY_ACTIVE_ARCH = YES; 275 | SDKROOT = iphoneos; 276 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 277 | TARGETED_DEVICE_FAMILY = "1,2"; 278 | VERSIONING_SYSTEM = "apple-generic"; 279 | VERSION_INFO_PREFIX = ""; 280 | }; 281 | name = Debug; 282 | }; 283 | CC71C1661BBDD4B500772EDB /* Release */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ALWAYS_SEARCH_USER_PATHS = NO; 287 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 288 | CLANG_CXX_LIBRARY = "libc++"; 289 | CLANG_ENABLE_MODULES = YES; 290 | CLANG_ENABLE_OBJC_ARC = YES; 291 | CLANG_WARN_BOOL_CONVERSION = YES; 292 | CLANG_WARN_CONSTANT_CONVERSION = YES; 293 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 294 | CLANG_WARN_EMPTY_BODY = YES; 295 | CLANG_WARN_ENUM_CONVERSION = YES; 296 | CLANG_WARN_INT_CONVERSION = YES; 297 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 298 | CLANG_WARN_UNREACHABLE_CODE = YES; 299 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 300 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 301 | COPY_PHASE_STRIP = NO; 302 | CURRENT_PROJECT_VERSION = 1; 303 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 304 | ENABLE_NS_ASSERTIONS = NO; 305 | ENABLE_STRICT_OBJC_MSGSEND = YES; 306 | GCC_C_LANGUAGE_STANDARD = gnu99; 307 | GCC_NO_COMMON_BLOCKS = YES; 308 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 309 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 310 | GCC_WARN_UNDECLARED_SELECTOR = YES; 311 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 312 | GCC_WARN_UNUSED_FUNCTION = YES; 313 | GCC_WARN_UNUSED_VARIABLE = YES; 314 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 315 | MTL_ENABLE_DEBUG_INFO = NO; 316 | SDKROOT = iphoneos; 317 | TARGETED_DEVICE_FAMILY = "1,2"; 318 | VALIDATE_PRODUCT = YES; 319 | VERSIONING_SYSTEM = "apple-generic"; 320 | VERSION_INFO_PREFIX = ""; 321 | }; 322 | name = Release; 323 | }; 324 | CC71C1681BBDD4B500772EDB /* Debug */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | CLANG_ENABLE_MODULES = YES; 328 | DEFINES_MODULE = YES; 329 | DYLIB_COMPATIBILITY_VERSION = 1; 330 | DYLIB_CURRENT_VERSION = 1; 331 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 332 | INFOPLIST_FILE = ArrayDiff/Info.plist; 333 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 334 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 335 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 336 | PRODUCT_BUNDLE_IDENTIFIER = adlai.ArrayDiff; 337 | PRODUCT_NAME = "$(TARGET_NAME)"; 338 | SKIP_INSTALL = YES; 339 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 340 | }; 341 | name = Debug; 342 | }; 343 | CC71C1691BBDD4B500772EDB /* Release */ = { 344 | isa = XCBuildConfiguration; 345 | buildSettings = { 346 | CLANG_ENABLE_MODULES = YES; 347 | DEFINES_MODULE = YES; 348 | DYLIB_COMPATIBILITY_VERSION = 1; 349 | DYLIB_CURRENT_VERSION = 1; 350 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 351 | INFOPLIST_FILE = ArrayDiff/Info.plist; 352 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 353 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 354 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 355 | PRODUCT_BUNDLE_IDENTIFIER = adlai.ArrayDiff; 356 | PRODUCT_NAME = "$(TARGET_NAME)"; 357 | SKIP_INSTALL = YES; 358 | }; 359 | name = Release; 360 | }; 361 | CC71C16B1BBDD4B500772EDB /* Debug */ = { 362 | isa = XCBuildConfiguration; 363 | buildSettings = { 364 | INFOPLIST_FILE = ArrayDiffTests/Info.plist; 365 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 366 | PRODUCT_BUNDLE_IDENTIFIER = adlai.ArrayDiffTests; 367 | PRODUCT_NAME = "$(TARGET_NAME)"; 368 | }; 369 | name = Debug; 370 | }; 371 | CC71C16C1BBDD4B500772EDB /* Release */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | INFOPLIST_FILE = ArrayDiffTests/Info.plist; 375 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 376 | PRODUCT_BUNDLE_IDENTIFIER = adlai.ArrayDiffTests; 377 | PRODUCT_NAME = "$(TARGET_NAME)"; 378 | }; 379 | name = Release; 380 | }; 381 | /* End XCBuildConfiguration section */ 382 | 383 | /* Begin XCConfigurationList section */ 384 | CC71C14D1BBDD4B400772EDB /* Build configuration list for PBXProject "ArrayDiff" */ = { 385 | isa = XCConfigurationList; 386 | buildConfigurations = ( 387 | CC71C1651BBDD4B500772EDB /* Debug */, 388 | CC71C1661BBDD4B500772EDB /* Release */, 389 | ); 390 | defaultConfigurationIsVisible = 0; 391 | defaultConfigurationName = Release; 392 | }; 393 | CC71C1671BBDD4B500772EDB /* Build configuration list for PBXNativeTarget "ArrayDiff" */ = { 394 | isa = XCConfigurationList; 395 | buildConfigurations = ( 396 | CC71C1681BBDD4B500772EDB /* Debug */, 397 | CC71C1691BBDD4B500772EDB /* Release */, 398 | ); 399 | defaultConfigurationIsVisible = 0; 400 | defaultConfigurationName = Release; 401 | }; 402 | CC71C16A1BBDD4B500772EDB /* Build configuration list for PBXNativeTarget "ArrayDiffTests" */ = { 403 | isa = XCConfigurationList; 404 | buildConfigurations = ( 405 | CC71C16B1BBDD4B500772EDB /* Debug */, 406 | CC71C16C1BBDD4B500772EDB /* Release */, 407 | ); 408 | defaultConfigurationIsVisible = 0; 409 | defaultConfigurationName = Release; 410 | }; 411 | /* End XCConfigurationList section */ 412 | }; 413 | rootObject = CC71C14A1BBDD4B400772EDB /* Project object */; 414 | } 415 | -------------------------------------------------------------------------------- /ArrayDiff.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ArrayDiff.xcodeproj/xcshareddata/xcschemes/ArrayDiff.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /ArrayDiff/ArrayDiff.h: -------------------------------------------------------------------------------- 1 | // 2 | // ArrayDiff.h 3 | // ArrayDiff 4 | // 5 | // Created by Adlai Holler on 10/1/15. 6 | // Copyright © 2015 Adlai Holler. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ArrayDiff. 12 | FOUNDATION_EXPORT double ArrayDiffVersionNumber; 13 | 14 | //! Project version string for ArrayDiff. 15 | FOUNDATION_EXPORT const unsigned char ArrayDiffVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ArrayDiff/ArrayDiff.swift: -------------------------------------------------------------------------------- 1 | 2 | import Foundation 3 | 4 | public struct ArrayDiff { 5 | static var debugLogging = false 6 | 7 | /// The indexes in the old array of the items that were kept 8 | public let commonIndexes: NSIndexSet 9 | /// The indexes in the old array of the items that were removed 10 | public let removedIndexes: NSIndexSet 11 | /// The indexes in the new array of the items that were inserted 12 | public let insertedIndexes: NSIndexSet 13 | 14 | /// Returns nil if the item was inserted 15 | public func oldIndexForNewIndex(index: Int) -> Int? { 16 | if insertedIndexes.containsIndex(index) { return nil } 17 | 18 | var result = index 19 | result -= insertedIndexes.countOfIndexesInRange(NSMakeRange(0, index)) 20 | result += removedIndexes.countOfIndexesInRange(NSMakeRange(0, result + 1)) 21 | return result 22 | } 23 | 24 | /// Returns nil if the item was deleted 25 | public func newIndexForOldIndex(index: Int) -> Int? { 26 | if removedIndexes.containsIndex(index) { return nil } 27 | 28 | var result = index 29 | let deletedBefore = removedIndexes.countOfIndexesInRange(NSMakeRange(0, index)) 30 | result -= deletedBefore 31 | var insertedAtOrBefore = 0 32 | for i in insertedIndexes { 33 | if i <= result { 34 | insertedAtOrBefore += 1 35 | result += 1 36 | } else { 37 | break 38 | } 39 | } 40 | if ArrayDiff.debugLogging { 41 | print("***Old -> New\n Removed \(removedIndexes)\n Inserted \(insertedIndexes)\n \(index) - \(deletedBefore) + \(insertedAtOrBefore) = \(result)\n") 42 | } 43 | 44 | return result 45 | } 46 | 47 | /** 48 | Returns true iff there are no changes to the items in this diff 49 | */ 50 | public var isEmpty: Bool { 51 | return removedIndexes.count == 0 && insertedIndexes.count == 0 52 | } 53 | } 54 | 55 | public extension Array { 56 | 57 | public func diff(other: Array, elementsAreEqual: ((Element, Element) -> Bool)) -> ArrayDiff { 58 | var lengths: [[Int]] = Array>( 59 | count: count + 1, 60 | repeatedValue: Array( 61 | count: other.count + 1, 62 | repeatedValue: 0) 63 | ) 64 | 65 | for i in (0...count).reverse() { 66 | for j in (0...other.count).reverse() { 67 | if i == count || j == other.count { 68 | lengths[i][j] = 0 69 | } else if elementsAreEqual(self[i], other[j]) { 70 | lengths[i][j] = 1 + lengths[i+1][j+1] 71 | } else { 72 | lengths[i][j] = max(lengths[i+1][j], lengths[i][j+1]) 73 | } 74 | } 75 | } 76 | let commonIndexes = NSMutableIndexSet() 77 | var i = 0, j = 0 78 | 79 | while i < count && j < other.count { 80 | if elementsAreEqual(self[i], other[j]) { 81 | commonIndexes.addIndex(i) 82 | i += 1 83 | j += 1 84 | } else if lengths[i+1][j] >= lengths[i][j+1] { 85 | i += 1 86 | } else { 87 | j += 1 88 | } 89 | } 90 | 91 | let removedIndexes = NSMutableIndexSet(indexesInRange: NSMakeRange(0, count)) 92 | removedIndexes.removeIndexes(commonIndexes) 93 | 94 | let commonObjects = self[commonIndexes] 95 | let addedIndexes = NSMutableIndexSet() 96 | i = 0 97 | j = 0 98 | 99 | while i < commonObjects.count || j < other.count { 100 | if i < commonObjects.count && j < other.count && elementsAreEqual (commonObjects[i], other[j]) { 101 | i += 1 102 | j += 1 103 | } else { 104 | addedIndexes.addIndex(j) 105 | j += 1 106 | } 107 | } 108 | 109 | return ArrayDiff(commonIndexes: commonIndexes, removedIndexes: removedIndexes, insertedIndexes: addedIndexes) 110 | } 111 | } 112 | 113 | public extension Array where Element: Equatable { 114 | public func diff(other: Array) -> ArrayDiff { 115 | return self.diff(other, elementsAreEqual: { $0 == $1 }) 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /ArrayDiff/FoundationExtensions.swift: -------------------------------------------------------------------------------- 1 | 2 | import Foundation 3 | 4 | // MARK: NSRange <-> Range conversion 5 | 6 | public extension NSRange { 7 | public var range: Range { 8 | return location..) { 12 | location = range.startIndex 13 | length = range.endIndex - range.startIndex 14 | } 15 | } 16 | 17 | // MARK: NSIndexSet -> [NSIndexPath] conversion 18 | 19 | public extension NSIndexSet { 20 | /** 21 | Returns an array of NSIndexPaths that correspond to these indexes in the given section. 22 | 23 | When reporting changes to table/collection view, you can improve performance by sorting 24 | deletes in descending order and inserts in ascending order. 25 | */ 26 | public func indexPathsInSection(section: Int, ascending: Bool = true) -> [NSIndexPath] { 27 | var result: [NSIndexPath] = [] 28 | result.reserveCapacity(count) 29 | enumerateIndexesWithOptions(ascending ? [] : .Reverse) { index, _ in 30 | result.append(NSIndexPath(indexes: [section, index], length: 2)) 31 | } 32 | return result 33 | } 34 | } 35 | 36 | // MARK: NSIndexSet support 37 | 38 | public extension Array { 39 | 40 | public subscript (indexes: NSIndexSet) -> [Element] { 41 | var result: [Element] = [] 42 | result.reserveCapacity(indexes.count) 43 | indexes.enumerateRangesUsingBlock { nsRange, _ in 44 | result += self[nsRange.range] 45 | } 46 | return result 47 | } 48 | 49 | public mutating func removeAtIndexes(indexSet: NSIndexSet) { 50 | indexSet.enumerateRangesWithOptions(.Reverse) { nsRange, _ in 51 | self.removeRange(nsRange.range) 52 | } 53 | } 54 | 55 | public mutating func insertElements(newElements: [Element], atIndexes indexes: NSIndexSet) { 56 | assert(indexes.count == newElements.count) 57 | var i = 0 58 | indexes.enumerateRangesUsingBlock { range, _ in 59 | self.insertContentsOf(newElements[i.. 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 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ArrayDiff/Section.swift: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | Types that conform to this protocol represent a section of a table. 4 | 5 | - See: `NamedSection` for an example implementation 6 | */ 7 | public protocol SectionType: Equatable { 8 | associatedtype Item: Equatable 9 | var items: [Item] { get } 10 | } 11 | 12 | public extension Array where Element: SectionType { 13 | /** 14 | For an array of SectionTypes, returns a compact list of the counts. This is useful for debugging changes. 15 | 16 | - Returns: A string like "" 17 | */ 18 | public var nestedDescription: String { 19 | let countsStr = enumerate().map { "[\($0): \($1.items.count)]" }.joinWithSeparator(", ") 20 | return "" 21 | } 22 | 23 | /** 24 | Attempt to retrieve the item at the given index path. Returns nil if the index is out of bounds. 25 | */ 26 | public subscript (indexPath: NSIndexPath) -> Element.Item? { 27 | let sectionIndex = indexPath.indexAtPosition(0) 28 | guard indices.contains(sectionIndex) else { return nil } 29 | 30 | let section = self[sectionIndex] 31 | let itemIndex = indexPath.indexAtPosition(1) 32 | guard section.items.indices.contains(itemIndex) else { return nil } 33 | 34 | return section.items[itemIndex] 35 | } 36 | } 37 | 38 | /** 39 | An example implementation of SectionType that uses a name to compare sections 40 | */ 41 | public struct BasicSection: SectionType { 42 | public var name: String 43 | public var items: [Item] 44 | 45 | public init(name: String, items: [Item]) { 46 | self.name = name 47 | self.items = items 48 | } 49 | } 50 | 51 | public func ==(section0: BasicSection, section1: BasicSection) -> Bool { 52 | return section0.name == section1.name 53 | } 54 | 55 | public struct NestedDiff { 56 | public let sectionsDiff: ArrayDiff 57 | public let itemDiffs: [ArrayDiff?] 58 | 59 | /** 60 | Determine the new index path, if any, for the given old index path. 61 | - Returns: The index path after the update, or nil if the item was removed 62 | */ 63 | public func newIndexPathForOldIndexPath(indexPath: NSIndexPath) -> NSIndexPath? { 64 | let oldSection = indexPath.indexAtPosition(0) 65 | if let newSection = sectionsDiff.newIndexForOldIndex(oldSection), 66 | newItem = itemDiffs[oldSection]?.newIndexForOldIndex(indexPath.indexAtPosition(1)) { 67 | return NSIndexPath(indexes: [newSection, newItem], length: 2) 68 | } else { 69 | return nil 70 | } 71 | } 72 | 73 | /** 74 | Determine the new index path, if any, for the given old index path. 75 | - Returns: The index path before the update, or nil if the item was inserted 76 | */ 77 | public func oldIndexPathForNewIndexPath(newIndexPath: NSIndexPath) -> NSIndexPath? { 78 | if let oldSection = sectionsDiff.oldIndexForNewIndex(newIndexPath.indexAtPosition(0)), 79 | oldItem = itemDiffs[oldSection]?.oldIndexForNewIndex(newIndexPath.indexAtPosition(1)) { 80 | return NSIndexPath(indexes: [oldSection, oldItem], length: 2) 81 | } else { 82 | return nil 83 | } 84 | } 85 | 86 | /** 87 | Returns true iff there are no changes to the sections or items in this diff 88 | */ 89 | public var isEmpty: Bool { 90 | return sectionsDiff.isEmpty && !itemDiffs.contains { diffOrNil in 91 | if let diff = diffOrNil { 92 | return !diff.isEmpty 93 | } else { 94 | return false 95 | } 96 | } 97 | } 98 | } 99 | 100 | public extension Array where Element: SectionType { 101 | /** 102 | Compute the diffs at the section level plus the item diffs for all sections that survived the change. 103 | Sections are considered equal if their metadatas are equal. 104 | 105 | 106 | - Parameter newData: The new array of Sections 107 | 108 | - Returns: The section-level diff plus item diffs for each section that was not removed/inserted. 109 | itemDiffs is indexed based on the _old_ section indexes. 110 | 111 | */ 112 | public func diffNested(newData: Array) -> NestedDiff { 113 | let sectionDiff = diff(newData) 114 | 115 | // diffs will exist for all sections that weren't deleted or inserted 116 | let itemDiffs: [ArrayDiff?] = self.enumerate().map { oldSectionIndex, oldSectionInfo in 117 | if let newSection = sectionDiff.newIndexForOldIndex(oldSectionIndex) { 118 | assert(newData[newSection] == oldSectionInfo, "Diffing for the wrong section!") 119 | return oldSectionInfo.items.diff(newData[newSection].items) 120 | } else { 121 | return nil 122 | } 123 | } 124 | 125 | return NestedDiff(sectionsDiff: sectionDiff, itemDiffs: itemDiffs) 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /ArrayDiff/UIKitIntegration.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIKitIntegration.swift 3 | // ArrayDiff 4 | // 5 | // Created by Adlai Holler on 10/3/15. 6 | // Copyright © 2015 Adlai Holler. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public extension ArrayDiff { 12 | /** 13 | Apply this diff to items in the given section of the collection view. 14 | 15 | This should be called on the main thread inside collectionView.performBatchUpdates 16 | */ 17 | public func applyToItemsInCollectionView(collectionView: UICollectionView, section: Int) { 18 | assert(NSThread.isMainThread()) 19 | // Apply updates in safe order for good measure. 20 | // Deletes, descending 21 | // Inserts, ascending 22 | collectionView.deleteItemsAtIndexPaths(removedIndexes.indexPathsInSection(section, ascending: false)) 23 | collectionView.insertItemsAtIndexPaths(insertedIndexes.indexPathsInSection(section)) 24 | } 25 | 26 | /** 27 | Apply this diff to rows in the given section of the table view. 28 | 29 | This should be called on the main thread between tableView.beginUpdates and tableView.endUpdates 30 | */ 31 | public func applyToRowsInTableView(tableView: UITableView, section: Int, rowAnimation: UITableViewRowAnimation) { 32 | assert(NSThread.isMainThread()) 33 | // Apply updates in safe order for good measure. 34 | // Deletes, descending 35 | // Inserts, ascending 36 | tableView.deleteRowsAtIndexPaths(removedIndexes.indexPathsInSection(section, ascending: false), withRowAnimation: rowAnimation) 37 | tableView.insertRowsAtIndexPaths(insertedIndexes.indexPathsInSection(section), withRowAnimation: rowAnimation) 38 | } 39 | 40 | /** 41 | Apply this diff to the sections of the table view. 42 | 43 | This should be called on the main thread between tableView.beginUpdates and tableView.endUpdates 44 | */ 45 | public func applyToSectionsInTableView(tableView: UITableView, rowAnimation: UITableViewRowAnimation) { 46 | assert(NSThread.isMainThread()) 47 | // Apply updates in safe order for good measure. 48 | // Deletes, descending 49 | // Inserts, ascending 50 | if removedIndexes.count > 0 { 51 | tableView.deleteSections(removedIndexes, withRowAnimation: rowAnimation) 52 | } 53 | if insertedIndexes.count > 0 { 54 | tableView.insertSections(insertedIndexes, withRowAnimation: rowAnimation) 55 | } 56 | } 57 | 58 | /** 59 | Apply this diff to the sections of the collection view. 60 | 61 | This should be called on the main thread inside collectionView.performBatchUpdates 62 | */ 63 | public func applyToSectionsInCollectionView(collectionView: UICollectionView) { 64 | assert(NSThread.isMainThread()) 65 | // Apply updates in safe order for good measure. 66 | // Deletes, descending 67 | // Inserts, ascending 68 | if removedIndexes.count > 0 { 69 | collectionView.deleteSections(removedIndexes) 70 | } 71 | if insertedIndexes.count > 0 { 72 | collectionView.insertSections(insertedIndexes) 73 | } 74 | } 75 | } 76 | 77 | public extension NestedDiff { 78 | /** 79 | Apply this nested diff to the given table view. 80 | 81 | This should be called on the main thread between tableView.beginUpdates and tableView.endUpdates 82 | */ 83 | public func applyToTableView(tableView: UITableView, rowAnimation: UITableViewRowAnimation) { 84 | assert(NSThread.isMainThread()) 85 | // Apply updates in safe order for good measure. 86 | // Item deletes, descending 87 | // Section deletes 88 | // Section inserts 89 | // Item inserts, ascending 90 | for (oldSection, diffOrNil) in itemDiffs.enumerate() { 91 | if let diff = diffOrNil { 92 | tableView.deleteRowsAtIndexPaths(diff.removedIndexes.indexPathsInSection(oldSection, ascending: false), withRowAnimation: rowAnimation) 93 | } 94 | } 95 | sectionsDiff.applyToSectionsInTableView(tableView, rowAnimation: rowAnimation) 96 | for (oldSection, diffOrNil) in itemDiffs.enumerate() { 97 | if let diff = diffOrNil { 98 | if let newSection = sectionsDiff.newIndexForOldIndex(oldSection) { 99 | tableView.insertRowsAtIndexPaths(diff.insertedIndexes.indexPathsInSection(newSection), withRowAnimation: rowAnimation) 100 | } else { 101 | assertionFailure("Found an item diff for a section that was removed. Wat.") 102 | } 103 | } 104 | } 105 | } 106 | 107 | /** 108 | Apply this nested diff to the given collection view. 109 | 110 | This should be called on the main thread inside collectionView.performBatchUpdates 111 | */ 112 | public func applyToCollectionView(collectionView: UICollectionView) { 113 | assert(NSThread.isMainThread()) 114 | // Apply updates in safe order for good measure. 115 | // Item deletes, descending 116 | // Section deletes 117 | // Section inserts 118 | // Item inserts, ascending 119 | for (oldSection, diffOrNil) in itemDiffs.enumerate() { 120 | if let diff = diffOrNil { 121 | collectionView.deleteItemsAtIndexPaths(diff.removedIndexes.indexPathsInSection(oldSection, ascending: false)) 122 | } 123 | } 124 | sectionsDiff.applyToSectionsInCollectionView(collectionView) 125 | for (oldSection, diffOrNil) in itemDiffs.enumerate() { 126 | if let diff = diffOrNil { 127 | if let newSection = sectionsDiff.newIndexForOldIndex(oldSection) { 128 | collectionView.insertItemsAtIndexPaths(diff.insertedIndexes.indexPathsInSection(newSection)) 129 | } else { 130 | assertionFailure("Found an item diff for a section that was removed. Wat.") 131 | } 132 | } 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /ArrayDiffTests/ArrayDiffTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ArrayDiffTests.swift 3 | // ArrayDiffTests 4 | // 5 | // Created by Adlai Holler on 10/1/15. 6 | // Copyright © 2015 Adlai Holler. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ArrayDiff 11 | 12 | class ArrayDiffTests: XCTestCase { 13 | 14 | func testACommonCase() { 15 | let old = "a b c d e".componentsSeparatedByString(" ") 16 | let new = "m a b f".componentsSeparatedByString(" ") 17 | 18 | let allFirstIndexes = NSIndexSet(indexesInRange: NSMakeRange(0, old.count)) 19 | 20 | let expectedRemoves = NSMutableIndexSet() 21 | expectedRemoves.addIndexesInRange(NSMakeRange(2, 3)) 22 | 23 | let expectedInserts = NSMutableIndexSet() 24 | expectedInserts.addIndex(0) 25 | expectedInserts.addIndex(3) 26 | 27 | 28 | let expectedCommonObjects = "a b".componentsSeparatedByString(" ") 29 | 30 | let diff = old.diff(new) 31 | 32 | XCTAssertEqual(expectedInserts, diff.insertedIndexes) 33 | XCTAssertEqual(expectedRemoves, diff.removedIndexes) 34 | XCTAssertEqual(expectedCommonObjects, old[diff.commonIndexes]) 35 | 36 | let removedPlusCommon = NSMutableIndexSet(indexSet: diff.removedIndexes) 37 | removedPlusCommon.addIndexes(diff.commonIndexes) 38 | XCTAssertEqual(removedPlusCommon, allFirstIndexes) 39 | 40 | var reconstructed = old 41 | reconstructed.removeAtIndexes(diff.removedIndexes) 42 | reconstructed.insertElements(new[diff.insertedIndexes], atIndexes: diff.insertedIndexes) 43 | XCTAssertEqual(reconstructed, new) 44 | } 45 | 46 | func testNewIndexForOldIndex() { 47 | let old = "a b c d e".componentsSeparatedByString(" ") 48 | let new = "m a b f".componentsSeparatedByString(" ") 49 | let diff = old.diff(new) 50 | let newIndexes: [Int?] = (0.. Bool { 106 | return t0.value == t1.value 107 | } 108 | } -------------------------------------------------------------------------------- /ArrayDiffTests/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B99123EA9EDC92D672B36C4C /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A8C5C4CE1B849F4DD20BD864 /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 11 | CC642FB81BC0620E0024AD39 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC642FB71BC0620E0024AD39 /* Utilities.swift */; settings = {ASSET_TAGS = (); }; }; 12 | CC71C17E1BBE16DA00772EDB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC71C17D1BBE16DA00772EDB /* AppDelegate.swift */; }; 13 | CC71C1801BBE16DA00772EDB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC71C17F1BBE16DA00772EDB /* ViewController.swift */; }; 14 | CC71C1831BBE16DA00772EDB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CC71C1811BBE16DA00772EDB /* Main.storyboard */; }; 15 | CC71C1851BBE16DA00772EDB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CC71C1841BBE16DA00772EDB /* Assets.xcassets */; }; 16 | CC71C1881BBE16DA00772EDB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CC71C1861BBE16DA00772EDB /* LaunchScreen.storyboard */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | A8C5C4CE1B849F4DD20BD864 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | CC500C041BBF684900F0D46A /* ArrayDiffExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ArrayDiffExample-Bridging-Header.h"; sourceTree = ""; }; 22 | CC642FB71BC0620E0024AD39 /* Utilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = ""; }; 23 | CC71C17A1BBE16DA00772EDB /* ArrayDiffExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ArrayDiffExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | CC71C17D1BBE16DA00772EDB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 25 | CC71C17F1BBE16DA00772EDB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 26 | CC71C1821BBE16DA00772EDB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | CC71C1841BBE16DA00772EDB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | CC71C1871BBE16DA00772EDB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | CC71C1891BBE16DA00772EDB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | E3A5B455C1F7070368012B13 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; 31 | FA1BF45B04DCE2098602C724 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | CC71C1771BBE16DA00772EDB /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | B99123EA9EDC92D672B36C4C /* Pods.framework in Frameworks */, 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 835C36A7AE470EDFD5D435A3 /* Pods */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | FA1BF45B04DCE2098602C724 /* Pods.debug.xcconfig */, 50 | E3A5B455C1F7070368012B13 /* Pods.release.xcconfig */, 51 | ); 52 | name = Pods; 53 | sourceTree = ""; 54 | }; 55 | CC71C1711BBE16DA00772EDB = { 56 | isa = PBXGroup; 57 | children = ( 58 | CC71C17C1BBE16DA00772EDB /* ArrayDiffExample */, 59 | CC71C17B1BBE16DA00772EDB /* Products */, 60 | 835C36A7AE470EDFD5D435A3 /* Pods */, 61 | FCCAE1297685F75E8801C542 /* Frameworks */, 62 | ); 63 | sourceTree = ""; 64 | }; 65 | CC71C17B1BBE16DA00772EDB /* Products */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | CC71C17A1BBE16DA00772EDB /* ArrayDiffExample.app */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | CC71C17C1BBE16DA00772EDB /* ArrayDiffExample */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | CC71C17D1BBE16DA00772EDB /* AppDelegate.swift */, 77 | CC71C17F1BBE16DA00772EDB /* ViewController.swift */, 78 | CC642FB71BC0620E0024AD39 /* Utilities.swift */, 79 | CC71C1811BBE16DA00772EDB /* Main.storyboard */, 80 | CC71C1841BBE16DA00772EDB /* Assets.xcassets */, 81 | CC71C1861BBE16DA00772EDB /* LaunchScreen.storyboard */, 82 | CC71C1891BBE16DA00772EDB /* Info.plist */, 83 | CC500C041BBF684900F0D46A /* ArrayDiffExample-Bridging-Header.h */, 84 | ); 85 | path = ArrayDiffExample; 86 | sourceTree = ""; 87 | }; 88 | FCCAE1297685F75E8801C542 /* Frameworks */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | A8C5C4CE1B849F4DD20BD864 /* Pods.framework */, 92 | ); 93 | name = Frameworks; 94 | sourceTree = ""; 95 | }; 96 | /* End PBXGroup section */ 97 | 98 | /* Begin PBXNativeTarget section */ 99 | CC71C1791BBE16DA00772EDB /* ArrayDiffExample */ = { 100 | isa = PBXNativeTarget; 101 | buildConfigurationList = CC71C18C1BBE16DA00772EDB /* Build configuration list for PBXNativeTarget "ArrayDiffExample" */; 102 | buildPhases = ( 103 | 0F51EC56221C4A84DB7112CA /* Check Pods Manifest.lock */, 104 | CC71C1761BBE16DA00772EDB /* Sources */, 105 | CC71C1771BBE16DA00772EDB /* Frameworks */, 106 | CC71C1781BBE16DA00772EDB /* Resources */, 107 | 3BDFB1C01D6681F5EE2CB90B /* Embed Pods Frameworks */, 108 | 7A9FDAB7EC115F34BEE62E15 /* Copy Pods Resources */, 109 | ); 110 | buildRules = ( 111 | ); 112 | dependencies = ( 113 | ); 114 | name = ArrayDiffExample; 115 | productName = ArrayDiffExample; 116 | productReference = CC71C17A1BBE16DA00772EDB /* ArrayDiffExample.app */; 117 | productType = "com.apple.product-type.application"; 118 | }; 119 | /* End PBXNativeTarget section */ 120 | 121 | /* Begin PBXProject section */ 122 | CC71C1721BBE16DA00772EDB /* Project object */ = { 123 | isa = PBXProject; 124 | attributes = { 125 | LastSwiftUpdateCheck = 0700; 126 | LastUpgradeCheck = 0700; 127 | ORGANIZATIONNAME = "Adlai Holler"; 128 | TargetAttributes = { 129 | CC71C1791BBE16DA00772EDB = { 130 | CreatedOnToolsVersion = 7.0.1; 131 | }; 132 | }; 133 | }; 134 | buildConfigurationList = CC71C1751BBE16DA00772EDB /* Build configuration list for PBXProject "ArrayDiffExample" */; 135 | compatibilityVersion = "Xcode 3.2"; 136 | developmentRegion = English; 137 | hasScannedForEncodings = 0; 138 | knownRegions = ( 139 | en, 140 | Base, 141 | ); 142 | mainGroup = CC71C1711BBE16DA00772EDB; 143 | productRefGroup = CC71C17B1BBE16DA00772EDB /* Products */; 144 | projectDirPath = ""; 145 | projectRoot = ""; 146 | targets = ( 147 | CC71C1791BBE16DA00772EDB /* ArrayDiffExample */, 148 | ); 149 | }; 150 | /* End PBXProject section */ 151 | 152 | /* Begin PBXResourcesBuildPhase section */ 153 | CC71C1781BBE16DA00772EDB /* Resources */ = { 154 | isa = PBXResourcesBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | CC71C1881BBE16DA00772EDB /* LaunchScreen.storyboard in Resources */, 158 | CC71C1851BBE16DA00772EDB /* Assets.xcassets in Resources */, 159 | CC71C1831BBE16DA00772EDB /* Main.storyboard in Resources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXResourcesBuildPhase section */ 164 | 165 | /* Begin PBXShellScriptBuildPhase section */ 166 | 0F51EC56221C4A84DB7112CA /* Check Pods Manifest.lock */ = { 167 | isa = PBXShellScriptBuildPhase; 168 | buildActionMask = 2147483647; 169 | files = ( 170 | ); 171 | inputPaths = ( 172 | ); 173 | name = "Check Pods Manifest.lock"; 174 | outputPaths = ( 175 | ); 176 | runOnlyForDeploymentPostprocessing = 0; 177 | shellPath = /bin/sh; 178 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 179 | showEnvVarsInLog = 0; 180 | }; 181 | 3BDFB1C01D6681F5EE2CB90B /* Embed Pods Frameworks */ = { 182 | isa = PBXShellScriptBuildPhase; 183 | buildActionMask = 2147483647; 184 | files = ( 185 | ); 186 | inputPaths = ( 187 | ); 188 | name = "Embed Pods Frameworks"; 189 | outputPaths = ( 190 | ); 191 | runOnlyForDeploymentPostprocessing = 0; 192 | shellPath = /bin/sh; 193 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n"; 194 | showEnvVarsInLog = 0; 195 | }; 196 | 7A9FDAB7EC115F34BEE62E15 /* Copy Pods Resources */ = { 197 | isa = PBXShellScriptBuildPhase; 198 | buildActionMask = 2147483647; 199 | files = ( 200 | ); 201 | inputPaths = ( 202 | ); 203 | name = "Copy Pods Resources"; 204 | outputPaths = ( 205 | ); 206 | runOnlyForDeploymentPostprocessing = 0; 207 | shellPath = /bin/sh; 208 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; 209 | showEnvVarsInLog = 0; 210 | }; 211 | /* End PBXShellScriptBuildPhase section */ 212 | 213 | /* Begin PBXSourcesBuildPhase section */ 214 | CC71C1761BBE16DA00772EDB /* Sources */ = { 215 | isa = PBXSourcesBuildPhase; 216 | buildActionMask = 2147483647; 217 | files = ( 218 | CC642FB81BC0620E0024AD39 /* Utilities.swift in Sources */, 219 | CC71C1801BBE16DA00772EDB /* ViewController.swift in Sources */, 220 | CC71C17E1BBE16DA00772EDB /* AppDelegate.swift in Sources */, 221 | ); 222 | runOnlyForDeploymentPostprocessing = 0; 223 | }; 224 | /* End PBXSourcesBuildPhase section */ 225 | 226 | /* Begin PBXVariantGroup section */ 227 | CC71C1811BBE16DA00772EDB /* Main.storyboard */ = { 228 | isa = PBXVariantGroup; 229 | children = ( 230 | CC71C1821BBE16DA00772EDB /* Base */, 231 | ); 232 | name = Main.storyboard; 233 | sourceTree = ""; 234 | }; 235 | CC71C1861BBE16DA00772EDB /* LaunchScreen.storyboard */ = { 236 | isa = PBXVariantGroup; 237 | children = ( 238 | CC71C1871BBE16DA00772EDB /* Base */, 239 | ); 240 | name = LaunchScreen.storyboard; 241 | sourceTree = ""; 242 | }; 243 | /* End PBXVariantGroup section */ 244 | 245 | /* Begin XCBuildConfiguration section */ 246 | CC71C18A1BBE16DA00772EDB /* Debug */ = { 247 | isa = XCBuildConfiguration; 248 | buildSettings = { 249 | ALWAYS_SEARCH_USER_PATHS = NO; 250 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 251 | CLANG_CXX_LIBRARY = "libc++"; 252 | CLANG_ENABLE_MODULES = YES; 253 | CLANG_ENABLE_OBJC_ARC = YES; 254 | CLANG_WARN_BOOL_CONVERSION = YES; 255 | CLANG_WARN_CONSTANT_CONVERSION = YES; 256 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 257 | CLANG_WARN_EMPTY_BODY = YES; 258 | CLANG_WARN_ENUM_CONVERSION = YES; 259 | CLANG_WARN_INT_CONVERSION = YES; 260 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 261 | CLANG_WARN_UNREACHABLE_CODE = YES; 262 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 263 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 264 | COPY_PHASE_STRIP = NO; 265 | DEBUG_INFORMATION_FORMAT = dwarf; 266 | ENABLE_STRICT_OBJC_MSGSEND = YES; 267 | ENABLE_TESTABILITY = YES; 268 | GCC_C_LANGUAGE_STANDARD = gnu99; 269 | GCC_DYNAMIC_NO_PIC = NO; 270 | GCC_NO_COMMON_BLOCKS = YES; 271 | GCC_OPTIMIZATION_LEVEL = 0; 272 | GCC_PREPROCESSOR_DEFINITIONS = ( 273 | "DEBUG=1", 274 | "$(inherited)", 275 | ); 276 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 277 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 278 | GCC_WARN_UNDECLARED_SELECTOR = YES; 279 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 280 | GCC_WARN_UNUSED_FUNCTION = YES; 281 | GCC_WARN_UNUSED_VARIABLE = YES; 282 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 283 | MTL_ENABLE_DEBUG_INFO = YES; 284 | ONLY_ACTIVE_ARCH = YES; 285 | SDKROOT = iphoneos; 286 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 287 | }; 288 | name = Debug; 289 | }; 290 | CC71C18B1BBE16DA00772EDB /* Release */ = { 291 | isa = XCBuildConfiguration; 292 | buildSettings = { 293 | ALWAYS_SEARCH_USER_PATHS = NO; 294 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 295 | CLANG_CXX_LIBRARY = "libc++"; 296 | CLANG_ENABLE_MODULES = YES; 297 | CLANG_ENABLE_OBJC_ARC = YES; 298 | CLANG_WARN_BOOL_CONVERSION = YES; 299 | CLANG_WARN_CONSTANT_CONVERSION = YES; 300 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 301 | CLANG_WARN_EMPTY_BODY = YES; 302 | CLANG_WARN_ENUM_CONVERSION = YES; 303 | CLANG_WARN_INT_CONVERSION = YES; 304 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 305 | CLANG_WARN_UNREACHABLE_CODE = YES; 306 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 307 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 308 | COPY_PHASE_STRIP = NO; 309 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 310 | ENABLE_NS_ASSERTIONS = NO; 311 | ENABLE_STRICT_OBJC_MSGSEND = YES; 312 | GCC_C_LANGUAGE_STANDARD = gnu99; 313 | GCC_NO_COMMON_BLOCKS = YES; 314 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 315 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 316 | GCC_WARN_UNDECLARED_SELECTOR = YES; 317 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 318 | GCC_WARN_UNUSED_FUNCTION = YES; 319 | GCC_WARN_UNUSED_VARIABLE = YES; 320 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 321 | MTL_ENABLE_DEBUG_INFO = NO; 322 | SDKROOT = iphoneos; 323 | VALIDATE_PRODUCT = YES; 324 | }; 325 | name = Release; 326 | }; 327 | CC71C18D1BBE16DA00772EDB /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | baseConfigurationReference = FA1BF45B04DCE2098602C724 /* Pods.debug.xcconfig */; 330 | buildSettings = { 331 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 332 | CLANG_ENABLE_MODULES = YES; 333 | GCC_OPTIMIZATION_LEVEL = s; 334 | INFOPLIST_FILE = ArrayDiffExample/Info.plist; 335 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 336 | PRODUCT_BUNDLE_IDENTIFIER = adlai.ArrayDiffExample; 337 | PRODUCT_NAME = "$(TARGET_NAME)"; 338 | SWIFT_OBJC_BRIDGING_HEADER = "ArrayDiffExample/ArrayDiffExample-Bridging-Header.h"; 339 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 340 | }; 341 | name = Debug; 342 | }; 343 | CC71C18E1BBE16DA00772EDB /* Release */ = { 344 | isa = XCBuildConfiguration; 345 | baseConfigurationReference = E3A5B455C1F7070368012B13 /* Pods.release.xcconfig */; 346 | buildSettings = { 347 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 348 | CLANG_ENABLE_MODULES = YES; 349 | INFOPLIST_FILE = ArrayDiffExample/Info.plist; 350 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 351 | PRODUCT_BUNDLE_IDENTIFIER = adlai.ArrayDiffExample; 352 | PRODUCT_NAME = "$(TARGET_NAME)"; 353 | SWIFT_OBJC_BRIDGING_HEADER = "ArrayDiffExample/ArrayDiffExample-Bridging-Header.h"; 354 | }; 355 | name = Release; 356 | }; 357 | /* End XCBuildConfiguration section */ 358 | 359 | /* Begin XCConfigurationList section */ 360 | CC71C1751BBE16DA00772EDB /* Build configuration list for PBXProject "ArrayDiffExample" */ = { 361 | isa = XCConfigurationList; 362 | buildConfigurations = ( 363 | CC71C18A1BBE16DA00772EDB /* Debug */, 364 | CC71C18B1BBE16DA00772EDB /* Release */, 365 | ); 366 | defaultConfigurationIsVisible = 0; 367 | defaultConfigurationName = Release; 368 | }; 369 | CC71C18C1BBE16DA00772EDB /* Build configuration list for PBXNativeTarget "ArrayDiffExample" */ = { 370 | isa = XCConfigurationList; 371 | buildConfigurations = ( 372 | CC71C18D1BBE16DA00772EDB /* Debug */, 373 | CC71C18E1BBE16DA00772EDB /* Release */, 374 | ); 375 | defaultConfigurationIsVisible = 0; 376 | defaultConfigurationName = Release; 377 | }; 378 | /* End XCConfigurationList section */ 379 | }; 380 | rootObject = CC71C1721BBE16DA00772EDB /* Project object */; 381 | } 382 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ArrayDiffExample 4 | // 5 | // Created by Adlai Holler on 10/1/15. 6 | // Copyright © 2015 Adlai Holler. 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: [NSObject: AnyObject]?) -> 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 throttle down OpenGL ES frame rates. 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 inactive 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 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample/ArrayDiffExample-Bridging-Header.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Adlai-Holler/ArrayDiff/5c6ee73b0cd70edb29392024001924198ca53e0e/Example/ArrayDiffExample/ArrayDiffExample-Bridging-Header.h -------------------------------------------------------------------------------- /Example/ArrayDiffExample/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/ArrayDiffExample/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 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample/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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample/Utilities.swift: -------------------------------------------------------------------------------- 1 | 2 | import UIKit 3 | 4 | extension NSIndexSet { 5 | // Get a random index set in a range 6 | static func randomIndexesInRange(range: Range, probability: Float) -> NSIndexSet { 7 | let result = NSMutableIndexSet() 8 | for i in range { 9 | if Bool.random(probability) { 10 | result.addIndex(i) 11 | } 12 | } 13 | return result 14 | } 15 | } 16 | 17 | extension Bool { 18 | static var trueCount = 0 19 | static var totalCount = 0 20 | static func random(probability: Float) -> Bool { 21 | let result = arc4random_uniform(100) < UInt32(probability * 100) 22 | if result { 23 | trueCount++ 24 | } 25 | totalCount++ 26 | return result 27 | } 28 | } 29 | 30 | extension String { 31 | static func random() -> String { 32 | return NSUUID().UUIDString 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Example/ArrayDiffExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ArrayDiffExample 4 | // 5 | // Created by Adlai Holler on 10/1/15. 6 | // Copyright © 2015 Adlai Holler. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ArrayDiff 11 | 12 | private let cellID = "cellID" 13 | 14 | class ViewController: UITableViewController { 15 | let dataSource = ThrashingDataSource() 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | title = "ArrayDiff Demo" 20 | navigationItem.rightBarButtonItem = UIBarButtonItem(title: "+100", style: .Plain, target: self, action: "updateTapped") 21 | dataSource.registerReusableViewsWithTableView(tableView) 22 | tableView?.dataSource = dataSource 23 | } 24 | 25 | @objc private func updateTapped() { 26 | for _ in 0..<100 { 27 | dataSource.enqueueRandomUpdate(tableView, completion: { dataSource in 28 | let operationCount = dataSource.updateQueue.operationCount 29 | self.title = operationCount > 0 ? String(operationCount) : "ArrayDiff Demo" 30 | }) 31 | } 32 | } 33 | 34 | } 35 | 36 | private func createRandomSections(count: Int) -> [BasicSection] { 37 | return (0.. BasicSection { 41 | return BasicSection(name: .random(), items: createRandomItems(count)) 42 | } 43 | 44 | private func createRandomItems(count: Int) -> [String] { 45 | return (0..] 51 | 52 | static var updateLogging = false 53 | let updateQueue: NSOperationQueue 54 | 55 | // The probability of each incremental update. 56 | var fickleness: Float = 0.1 57 | 58 | override init() { 59 | updateQueue = NSOperationQueue() 60 | updateQueue.maxConcurrentOperationCount = 1 61 | updateQueue.qualityOfService = .UserInitiated 62 | 63 | let initialSectionCount = 5 64 | data = createRandomSections(initialSectionCount) 65 | super.init() 66 | updateQueue.name = "\(self).updateQueue" 67 | } 68 | 69 | func enqueueRandomUpdate(tableView: UITableView, completion: (ThrashingDataSource -> Void)) { 70 | updateQueue.addOperationWithBlock { 71 | self.executeRandomUpdate(tableView) 72 | NSOperationQueue.mainQueue().addOperationWithBlock { 73 | completion(self) 74 | } 75 | } 76 | } 77 | 78 | private func executeRandomUpdate(tableView: UITableView) { 79 | if ThrashingDataSource.updateLogging { 80 | print("Data before update: \(data.nestedDescription)") 81 | } 82 | 83 | var newData = data 84 | 85 | let minimumSectionCount = 3 86 | let minimumItemCount = 5 87 | 88 | let _deletedItems: [NSIndexSet] = newData.enumerate().map { sectionIndex, sectionInfo in 89 | if sectionInfo.items.count >= minimumItemCount { 90 | let indexSet = NSIndexSet.randomIndexesInRange(0..= minimumSectionCount { 100 | _deletedSections = NSIndexSet.randomIndexesInRange(0.. String? { 153 | return data[section].name 154 | } 155 | 156 | func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 157 | let cell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath) 158 | cell.textLabel?.text = data[indexPath.section].items[indexPath.item] 159 | return cell 160 | } 161 | 162 | func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 163 | return data[section].items.count 164 | } 165 | 166 | func numberOfSectionsInTableView(tableView: UITableView) -> Int { 167 | return data.count 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '8.0' 2 | 3 | use_frameworks! 4 | 5 | pod 'ArrayDiff', :path => '../' 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Adlai Holler 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ArrayDiff [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Pods](https://cocoapod-badges.herokuapp.com/v/ArrayDiff/badge.png) ![Pod platforms](https://cocoapod-badges.herokuapp.com/p/ArrayDiff/badge.png) 2 | 3 | An efficient Swift utility to compute the difference between two arrays. Get the `removedIndexes` and `insertedIndexes` and pass them directly along to `UITableView` or `UICollectionView` when you update your data! The [diffing algorithm](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem) is the same that powers the `diff` utility – it's robust and quick. 4 | 5 | ## Basic Example 6 | 7 | ```swift 8 | let old = [ "a", "b", "c", "d" ] 9 | let new = [ "a", "c", "e", "f", "d" ] 10 | 11 | let diff = old.diff(new) 12 | // diff.removedIndexes = { 1 } 13 | // diff.insertedIndexes = { 2, 3 } 14 | 15 | // To update rows in section 0: 16 | tableView.beginUpdates() 17 | self.data = new 18 | diff.applyToRowsInTableView(tableView, section: 0, rowAnimation: .Automatic) 19 | tableView.endUpdates() 20 | 21 | // Or to update sections: 22 | tableView.beginUpdates() 23 | self.data = new 24 | diff.applyToSectionsInTableView(tableView, rowAnimation: .Automatic) 25 | tableView.endUpdates() 26 | ``` 27 | 28 | ## Nested Diff 29 | 30 | You can use types that conform to `SectionType` to perform nested row- and section-level diffs simultaneously: 31 | 32 | ```swift 33 | let old = [ 34 | BasicSection(name: "Alpha", items: ["a", "b", "c", "d", "e"]), 35 | BasicSection(name: "Bravo", items: ["f", "g", "h", "i", "j"]), 36 | BasicSection(name: "Charlie", items: ["k", "l", "m", "n", "o"]) 37 | ] 38 | let new = [ 39 | BasicSection(name: "Alpha", items: ["a", "b", "d", "e", "x"]), 40 | BasicSection(name: "Charlie", items: ["f", "g", "h", "i", "j"]), 41 | BasicSection(name: "Delta", items: ["f", "g", "h", "i", "j"]) 42 | ] 43 | 44 | let nestedDiff = old.diffNested(new) 45 | // nestedDiff.sectionsDiff.removedIndexes == {1} 46 | // nestedDiff.sectionsDiff.insertedIndexes == {2} 47 | // nestedDiff.itemDiffs[0].removedIndexes == {2} 48 | // nestedDiff.itemDiffs[0].insertedIndexes == {5} 49 | // etc. 50 | 51 | tableView.beginUpdates() 52 | self.data = new 53 | nestedDiff.applyToTableView(tableView, rowAnimation: .Automatic) 54 | tableView.endUpdates() 55 | ``` 56 | 57 | ## Limitations 58 | 59 | Item moves are treated as remove/insert, so when they are animated the cell will "teleport" to its new position, rather than sliding there. If you would like this feature, let me know in the Issues! 60 | 61 | ## Example Project 62 | 63 | Check out the iOS app in the Example folder to see this framework pushed to its limits to drive a UITableView. In it we have a table view with 20 sections of strings. When you tap update, the data is randomly updated and we assert that the changes we made are equal to the changes that the framework recovers by comparing the two arrays. 64 | 65 | ## Attribution 66 | 67 | Thanks to https://github.com/khanlou/NSArray-LongestCommonSubsequence which I ~~took inspiration~~ totally copied from. 68 | --------------------------------------------------------------------------------