diff --git a/.gitignore b/.gitignore index 080b743f..94b84e3a 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ Carthage/Build .build/ Packages/ +.swiftpm/ diff --git a/.gitmodules b/.gitmodules index 64fc6885..b672b015 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "Examples/RxSwift"] - path = Examples/RxSwift +[submodule "Carthage/Checkouts/RxSwift"] url = https://github.com/ReactiveX/RxSwift.git + path = Carthage/Checkouts/RxSwift diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 5186d070..00000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -4.0 diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 00000000..8e5f215f --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,37 @@ +included: + - Sources + - Tests +opt_in_rules: + - overridden_super_call + - private_outlet + - prohibited_super_call + - first_where + - closure_spacing + - unneeded_parentheses_in_closure_argument + - redundant_nil_coalescing + - pattern_matching_keywords + - explicit_init + - contains_over_first_not_nil +disabled_rules: + - line_length + - trailing_whitespace + - type_name + - identifier_name + - vertical_whitespace + - trailing_newline + - opening_brace + - large_tuple + - file_length + - comma + - colon + - private_over_fileprivate + - force_cast + - force_try + - function_parameter_count + - statement_position + - legacy_hashing + - todo + - operator_whitespace + - type_body_length + - function_body_length + - cyclomatic_complexity diff --git a/.travis.yml b/.travis.yml index 52b98c41..97e32804 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: objective-c -osx_image: xcode10 +osx_image: xcode11.5 notifications: slack: rxswift:3ykt2Z61f8GkdvhCZTYPduOL @@ -9,9 +9,10 @@ notifications: install: true env: - - BUILD="pushd Examples && ./dependencies.sh && set -o pipefail && (xcodebuild -project Example.xcodeproj -scheme ExampleUITests -configuration Release -destination 'platform=iOS Simulator,name=iPhone 7' test && xcodebuild -project Example.xcodeproj -scheme Example -configuration Release -destination 'platform=iOS Simulator,name=iPhone 7' build) | xcpretty" - - BUILD="carthage update --platform ios && set -o pipefail && (xcodebuild -project RxDataSources.xcodeproj -scheme Tests -configuration Release -destination 'platform=iOS Simulator,name=iPhone 7' test) | xcpretty" - - BUILD="gem install cocoapods --pre --no-rdoc --no-ri --no-document --quiet; pod repo update && pod lib lint RxDataSources.podspec --verbose && pod lib lint Differentiator.podspec --verbose " + - BUILD="brew install swiftlint" + - BUILD="carthage update --platform iOS && pushd Examples && set -o pipefail && (xcodebuild -project Example.xcodeproj -scheme ExampleUITests -configuration Release -destination 'platform=iOS Simulator,name=iPhone 8' test && xcodebuild -project Example.xcodeproj -scheme Example -configuration Release -destination 'platform=iOS Simulator,name=iPhone 8' build) | xcpretty" + - BUILD="carthage update --platform iOS && set -o pipefail && (xcodebuild -project RxDataSources.xcodeproj -scheme Tests -configuration Release -destination 'platform=iOS Simulator,name=iPhone 8' test) | xcpretty" + - BUILD="gem install cocoapods --pre --no-document --quiet; pod repo update && pod lib lint RxDataSources.podspec --verbose && pod lib lint Differentiator.podspec --verbose " - BUILD="carthage update --platform iOS && carthage build --no-skip-current --platform iOS" - BUILD="carthage update --platform tvOS && carthage build --no-skip-current --platform tvOS" - BUILD="swift test" diff --git a/CHANGELOG.md b/CHANGELOG.md index 05d774b4..dd292d25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,22 @@ All notable changes to this project will be documented in this file. --- -#### Enhancements -* Reduce computational complexity. #242 -* Adapted for RxSwift 4.2 +#### Unreleased + +* Fixes xcodeproj and submodule structure to avoid duplicate symbols and properly build for Carthage #392 +* Adds support of mutable CellViewModels. +* Changes `TableViewSectionedDataSource` default parameters `canEditRowAtIndexPath` and `canMoveRowAtIndexPath` to align with iOS default behavior #383 + +## [4.0.1](https://github.com/RxSwiftCommunity/RxDataSources/releases/tag/4.0.1) + +* Fixes Carthage integration and reverts static frameworks to dynamic frameworks. + +## [4.0.0](https://github.com/RxSwiftCommunity/RxDataSources/releases/tag/4.0.0) + +* Swift 5.0 +* Fixes problems with `UICollectionView` animation crashes. +* Improves readability by renaming short generic names to more descriptive names. +* Changes frameworks to be static libs. (Carthage integration) ## [3.1.0](https://github.com/RxSwiftCommunity/RxDataSources/releases/tag/3.1.0) @@ -117,7 +130,7 @@ This can break your code if you've implemented those extensions locally. This ca #### Features * Swift 2.3 compatible -* Improves mutability checkes. If data source is being mutated after binding, warning assert is triggered. +* Improves mutability checks. If data source is being mutated after binding, warning assert is triggered. * Deprecates `cellFactory` in favor of `configureCell`. * Improves runtime checks in DEBUG mode for correct `SectionModelType.init` implementation. diff --git a/Cartfile b/Cartfile index 4cb3fb31..bcb35918 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveX/RxSwift" ~> 4.0 +github "ReactiveX/RxSwift" ~> 6.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index e14f0d4c..c07923a0 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -git "/Users/kzaher/Projects/RxSwift" "4.3.0" +github "ReactiveX/RxSwift" "6.0.0" diff --git a/Carthage/Checkouts/RxSwift b/Carthage/Checkouts/RxSwift new file mode 160000 index 00000000..c8742ed9 --- /dev/null +++ b/Carthage/Checkouts/RxSwift @@ -0,0 +1 @@ +Subproject commit c8742ed97fc2f0c015a5ea5eddefb064cd7532d2 diff --git a/Differentiator.podspec b/Differentiator.podspec index 2dbe72b9..00760e90 100644 --- a/Differentiator.podspec +++ b/Differentiator.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Differentiator" - s.version = "3.1.0" + s.version = "5.0.0" s.summary = "Diff algorithm for UITableView and UICollectionView." s.description = <<-DESC Diff algorithm for UITableView and UICollectionView. @@ -12,11 +12,12 @@ Pod::Spec.new do |s| s.author = { "Krunoslav Zaher" => "krunoslav.zaher@gmail.com" } s.source = { :git => "https://github.com/RxSwiftCommunity/RxDataSources.git", :tag => s.version.to_s } - s.requires_arc = true + s.requires_arc = true + s.swift_version = '5.0' s.source_files = 'Sources/Differentiator/**/*.swift' - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '9.0' s.tvos.deployment_target = '9.0' end diff --git a/Examples/Example.xcodeproj/project.pbxproj b/Examples/Example.xcodeproj/project.pbxproj index 4d0ee2e1..7bd0bd7e 100644 --- a/Examples/Example.xcodeproj/project.pbxproj +++ b/Examples/Example.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1E38DA572278D39400C07A09 /* RxRelay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E38DA562278D39400C07A09 /* RxRelay.framework */; }; + 1E38DA582278D39400C07A09 /* RxRelay.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1E38DA562278D39400C07A09 /* RxRelay.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 845F61F41CCFD96800A8BE32 /* Example4_DifferentSectionAndItemTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845F61F31CCFD96800A8BE32 /* Example4_DifferentSectionAndItemTypes.swift */; }; 845F61F71CCFDE6A00A8BE32 /* ImageTitleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845F61F61CCFDE6A00A8BE32 /* ImageTitleTableViewCell.swift */; }; 845F61F91CCFDEA800A8BE32 /* TitleSwitchTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845F61F81CCFDEA800A8BE32 /* TitleSwitchTableViewCell.swift */; }; @@ -63,6 +65,20 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 1E38DA552278D39400C07A09 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = A2897D53225CA1E7004EA481; + remoteInfo = RxRelay; + }; + 1E38DA592278D39400C07A09 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = A2897CB3225CA1E7004EA481; + remoteInfo = RxRelay; + }; C82C3C591F3B937500309AE8 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C8984C511C36AF35001E4272 /* Project object */; @@ -77,41 +93,6 @@ remoteGlobalIDString = C82C3C531F3B937500309AE8; remoteInfo = Differentiator; }; - C82C3C9C1F3B93D900309AE8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C8984C511C36AF35001E4272 /* Project object */; - proxyType = 1; - remoteGlobalIDString = C87C345C1F36352600DB85FE; - remoteInfo = Dependencies; - }; - C85CB0C41F4349E6005CE91A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C8984C511C36AF35001E4272 /* Project object */; - proxyType = 1; - remoteGlobalIDString = C87C345C1F36352600DB85FE; - remoteInfo = Dependencies; - }; - C85CB0C61F434A80005CE91A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C8984C511C36AF35001E4272 /* Project object */; - proxyType = 1; - remoteGlobalIDString = C87C345C1F36352600DB85FE; - remoteInfo = Dependencies; - }; - C85CB0C81F434A83005CE91A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C8984C511C36AF35001E4272 /* Project object */; - proxyType = 1; - remoteGlobalIDString = C87C345C1F36352600DB85FE; - remoteInfo = Dependencies; - }; - C87C34601F36353300DB85FE /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C8984C511C36AF35001E4272 /* Project object */; - proxyType = 1; - remoteGlobalIDString = C87C345C1F36352600DB85FE; - remoteInfo = Dependencies; - }; C87C34641F36353B00DB85FE /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C8984C511C36AF35001E4272 /* Project object */; @@ -126,27 +107,6 @@ remoteGlobalIDString = C8A56AD71AD7424700B4673B; remoteInfo = "RxSwift-iOS"; }; - C88AC716214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C88BB8711B07E5ED0064D411; - remoteInfo = "RxSwift-macOS"; - }; - C88AC718214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2EA280C1BB9B5A200880ED3; - remoteInfo = "RxSwift-tvOS"; - }; - C88AC71A214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C8F0C0021BBBFB8B001B112F; - remoteInfo = "RxSwift-watchOS"; - }; C88AC71C214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; @@ -154,27 +114,6 @@ remoteGlobalIDString = C809396D1B8A71760088E94D; remoteInfo = "RxCocoa-iOS"; }; - C88AC71E214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C80939E71B8A71840088E94D; - remoteInfo = "RxCocoa-macOS"; - }; - C88AC720214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2138C751BB9BE9800339B5C; - remoteInfo = "RxCocoa-tvOS"; - }; - C88AC722214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C8F0C04B1BBBFBB9001B112F; - remoteInfo = "RxCocoa-watchOS"; - }; C88AC724214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; @@ -182,27 +121,6 @@ remoteGlobalIDString = C8093BC71B8A71F00088E94D; remoteInfo = "RxBlocking-iOS"; }; - C88AC726214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C8093C451B8A71FC0088E94D; - remoteInfo = "RxBlocking-macOS"; - }; - C88AC728214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D2EBEB811BB9B99D003A27DC; - remoteInfo = "RxBlocking-tvOS"; - }; - C88AC72A214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C8F0C0581BBBFBCE001B112F; - remoteInfo = "RxBlocking-watchOS"; - }; C88AC72C214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; @@ -210,27 +128,6 @@ remoteGlobalIDString = C88FA50C1C25C44800CCFEA4; remoteInfo = "RxTest-iOS"; }; - C88AC72E214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C88FA51D1C25C4B500CCFEA4; - remoteInfo = "RxTest-macOS"; - }; - C88AC730214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C88FA52E1C25C4C000CCFEA4; - remoteInfo = "RxTest-tvOS"; - }; - C88AC732214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = C88FA53F1C25C4CC00CCFEA4; - remoteInfo = "RxTest-watchOS"; - }; C88AC734214D9BA800C1A3E5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C88AC6FC214D9BA800C1A3E5 /* Rx.xcodeproj */; @@ -300,6 +197,7 @@ C87C34A31F363B3000DB85FE /* RxDataSources.framework in Embed Frameworks */, C82C3C5C1F3B937500309AE8 /* Differentiator.framework in Embed Frameworks */, C8241D7D214E75C6008C463E /* RxSwift.framework in Embed Frameworks */, + 1E38DA582278D39400C07A09 /* RxRelay.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -321,7 +219,6 @@ C81FBF611F3B9DC00094061E /* IntegerType+IdentifiableType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "IntegerType+IdentifiableType.swift"; sourceTree = ""; }; C81FBF621F3B9DC00094061E /* String+IdentifiableType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+IdentifiableType.swift"; sourceTree = ""; }; C81FBF651F3B9DF60094061E /* AnimationConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimationConfiguration.swift; sourceTree = ""; }; - C82541851F363C76009F6C03 /* dependencies.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = dependencies.sh; sourceTree = ""; }; C82C3C541F3B937500309AE8 /* Differentiator.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Differentiator.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C82C3C611F3B938C00309AE8 /* AnimatableSectionModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimatableSectionModel.swift; sourceTree = ""; }; C82C3C621F3B938C00309AE8 /* AnimatableSectionModelType+ItemPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AnimatableSectionModelType+ItemPath.swift"; sourceTree = ""; }; @@ -395,6 +292,7 @@ files = ( C87C34A21F363B3000DB85FE /* RxDataSources.framework in Frameworks */, C82C3C5B1F3B937500309AE8 /* Differentiator.framework in Frameworks */, + 1E38DA572278D39400C07A09 /* RxRelay.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -463,21 +361,10 @@ isa = PBXGroup; children = ( C88AC715214D9BA800C1A3E5 /* RxSwift.framework */, - C88AC717214D9BA800C1A3E5 /* RxSwift.framework */, - C88AC719214D9BA800C1A3E5 /* RxSwift.framework */, - C88AC71B214D9BA800C1A3E5 /* RxSwift.framework */, C88AC71D214D9BA800C1A3E5 /* RxCocoa.framework */, - C88AC71F214D9BA800C1A3E5 /* RxCocoa.framework */, - C88AC721214D9BA800C1A3E5 /* RxCocoa.framework */, - C88AC723214D9BA800C1A3E5 /* RxCocoa.framework */, + 1E38DA562278D39400C07A09 /* RxRelay.framework */, C88AC725214D9BA800C1A3E5 /* RxBlocking.framework */, - C88AC727214D9BA800C1A3E5 /* RxBlocking.framework */, - C88AC729214D9BA800C1A3E5 /* RxBlocking.framework */, - C88AC72B214D9BA800C1A3E5 /* RxBlocking.framework */, C88AC72D214D9BA800C1A3E5 /* RxTest.framework */, - C88AC72F214D9BA800C1A3E5 /* RxTest.framework */, - C88AC731214D9BA800C1A3E5 /* RxTest.framework */, - C88AC733214D9BA800C1A3E5 /* RxTest.framework */, C88AC735214D9BA800C1A3E5 /* AllTests-iOS.xctest */, C88AC737214D9BA800C1A3E5 /* AllTests-tvOS.xctest */, C88AC739214D9BA800C1A3E5 /* AllTests-macOS.xctest */, @@ -490,7 +377,6 @@ C8984C501C36AF35001E4272 = { isa = PBXGroup; children = ( - C82541851F363C76009F6C03 /* dependencies.sh */, C85EE5461C36F1FC0090614D /* Sources */, C8984C9C1C36B6FA001E4272 /* Example */, C8984CB21C36B723001E4272 /* ExampleUITests */, @@ -584,22 +470,6 @@ }; /* End PBXHeadersBuildPhase section */ -/* Begin PBXLegacyTarget section */ - C87C345C1F36352600DB85FE /* Dependencies */ = { - isa = PBXLegacyTarget; - buildArgumentsString = "$(ACTION)"; - buildConfigurationList = C87C345D1F36352600DB85FE /* Build configuration list for PBXLegacyTarget "Dependencies" */; - buildPhases = ( - ); - buildToolPath = ./dependencies.sh; - dependencies = ( - ); - name = Dependencies; - passBuildSettingsInEnvironment = 1; - productName = Dependencies; - }; -/* End PBXLegacyTarget section */ - /* Begin PBXNativeTarget section */ C81905AD1DEA019100AE679C /* Tests */ = { isa = PBXNativeTarget; @@ -612,7 +482,6 @@ buildRules = ( ); dependencies = ( - C85CB0C51F4349E6005CE91A /* PBXTargetDependency */, ); name = Tests; productName = Tests; @@ -631,7 +500,6 @@ buildRules = ( ); dependencies = ( - C82C3C9D1F3B93D900309AE8 /* PBXTargetDependency */, ); name = Differentiator; productName = Differentiator; @@ -653,7 +521,6 @@ C88AC73F214D9BF800C1A3E5 /* PBXTargetDependency */, C88AC741214D9BF800C1A3E5 /* PBXTargetDependency */, C82C3C9B1F3B93D200309AE8 /* PBXTargetDependency */, - C87C34611F36353300DB85FE /* PBXTargetDependency */, ); name = RxDataSources; productName = RxDataSources; @@ -673,9 +540,9 @@ buildRules = ( ); dependencies = ( - C85CB0C91F434A83005CE91A /* PBXTargetDependency */, C87C34651F36353B00DB85FE /* PBXTargetDependency */, C82C3C5A1F3B937500309AE8 /* PBXTargetDependency */, + 1E38DA5A2278D39400C07A09 /* PBXTargetDependency */, ); name = Example; productName = Example; @@ -693,7 +560,6 @@ buildRules = ( ); dependencies = ( - C85CB0C71F434A80005CE91A /* PBXTargetDependency */, C8984CB71C36B723001E4272 /* PBXTargetDependency */, ); name = ExampleUITests; @@ -708,7 +574,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0810; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = kzaher; TargetAttributes = { C81905AD1DEA019100AE679C = { @@ -720,11 +586,6 @@ CreatedOnToolsVersion = 8.3.3; ProvisioningStyle = Automatic; }; - C87C345C1F36352600DB85FE = { - CreatedOnToolsVersion = 8.3.3; - DevelopmentTeam = 783T66X79Y; - ProvisioningStyle = Automatic; - }; C8984C591C36AF35001E4272 = { CreatedOnToolsVersion = 7.2; }; @@ -742,6 +603,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -761,38 +623,23 @@ C8984C9A1C36B6FA001E4272 /* Example */, C8984CB01C36B723001E4272 /* ExampleUITests */, C81905AD1DEA019100AE679C /* Tests */, - C87C345C1F36352600DB85FE /* Dependencies */, ); }; /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - C88AC715214D9BA800C1A3E5 /* RxSwift.framework */ = { + 1E38DA562278D39400C07A09 /* RxRelay.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; - path = RxSwift.framework; - remoteRef = C88AC714214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - C88AC717214D9BA800C1A3E5 /* RxSwift.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxSwift.framework; - remoteRef = C88AC716214D9BA800C1A3E5 /* PBXContainerItemProxy */; + path = RxRelay.framework; + remoteRef = 1E38DA552278D39400C07A09 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - C88AC719214D9BA800C1A3E5 /* RxSwift.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxSwift.framework; - remoteRef = C88AC718214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - C88AC71B214D9BA800C1A3E5 /* RxSwift.framework */ = { + C88AC715214D9BA800C1A3E5 /* RxSwift.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; path = RxSwift.framework; - remoteRef = C88AC71A214D9BA800C1A3E5 /* PBXContainerItemProxy */; + remoteRef = C88AC714214D9BA800C1A3E5 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; C88AC71D214D9BA800C1A3E5 /* RxCocoa.framework */ = { @@ -802,27 +649,6 @@ remoteRef = C88AC71C214D9BA800C1A3E5 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - C88AC71F214D9BA800C1A3E5 /* RxCocoa.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxCocoa.framework; - remoteRef = C88AC71E214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - C88AC721214D9BA800C1A3E5 /* RxCocoa.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxCocoa.framework; - remoteRef = C88AC720214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - C88AC723214D9BA800C1A3E5 /* RxCocoa.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxCocoa.framework; - remoteRef = C88AC722214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; C88AC725214D9BA800C1A3E5 /* RxBlocking.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; @@ -830,27 +656,6 @@ remoteRef = C88AC724214D9BA800C1A3E5 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - C88AC727214D9BA800C1A3E5 /* RxBlocking.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxBlocking.framework; - remoteRef = C88AC726214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - C88AC729214D9BA800C1A3E5 /* RxBlocking.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxBlocking.framework; - remoteRef = C88AC728214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - C88AC72B214D9BA800C1A3E5 /* RxBlocking.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxBlocking.framework; - remoteRef = C88AC72A214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; C88AC72D214D9BA800C1A3E5 /* RxTest.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; @@ -858,27 +663,6 @@ remoteRef = C88AC72C214D9BA800C1A3E5 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - C88AC72F214D9BA800C1A3E5 /* RxTest.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxTest.framework; - remoteRef = C88AC72E214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - C88AC731214D9BA800C1A3E5 /* RxTest.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxTest.framework; - remoteRef = C88AC730214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - C88AC733214D9BA800C1A3E5 /* RxTest.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = RxTest.framework; - remoteRef = C88AC732214D9BA800C1A3E5 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; C88AC735214D9BA800C1A3E5 /* AllTests-iOS.xctest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; @@ -1055,6 +839,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 1E38DA5A2278D39400C07A09 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = RxRelay; + targetProxy = 1E38DA592278D39400C07A09 /* PBXContainerItemProxy */; + }; C82C3C5A1F3B937500309AE8 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = C82C3C531F3B937500309AE8 /* Differentiator */; @@ -1065,31 +854,6 @@ target = C82C3C531F3B937500309AE8 /* Differentiator */; targetProxy = C82C3C9A1F3B93D200309AE8 /* PBXContainerItemProxy */; }; - C82C3C9D1F3B93D900309AE8 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = C87C345C1F36352600DB85FE /* Dependencies */; - targetProxy = C82C3C9C1F3B93D900309AE8 /* PBXContainerItemProxy */; - }; - C85CB0C51F4349E6005CE91A /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = C87C345C1F36352600DB85FE /* Dependencies */; - targetProxy = C85CB0C41F4349E6005CE91A /* PBXContainerItemProxy */; - }; - C85CB0C71F434A80005CE91A /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = C87C345C1F36352600DB85FE /* Dependencies */; - targetProxy = C85CB0C61F434A80005CE91A /* PBXContainerItemProxy */; - }; - C85CB0C91F434A83005CE91A /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = C87C345C1F36352600DB85FE /* Dependencies */; - targetProxy = C85CB0C81F434A83005CE91A /* PBXContainerItemProxy */; - }; - C87C34611F36353300DB85FE /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = C87C345C1F36352600DB85FE /* Dependencies */; - targetProxy = C87C34601F36353300DB85FE /* PBXContainerItemProxy */; - }; C87C34651F36353B00DB85FE /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = C8984C591C36AF35001E4272 /* RxDataSources */; @@ -1146,6 +910,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.rx.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1163,6 +928,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.rx.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1181,11 +947,13 @@ INFOPLIST_FILE = Sources/Differentiator/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MACH_O_TYPE = staticlib; PRODUCT_BUNDLE_IDENTIFIER = org.rxswiftcommunity.Differentiator; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1204,42 +972,13 @@ INFOPLIST_FILE = Sources/Differentiator/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MACH_O_TYPE = staticlib; PRODUCT_BUNDLE_IDENTIFIER = org.rxswiftcommunity.Differentiator; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - }; - name = Release; - }; - C87C345E1F36352600DB85FE /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - DEBUGGING_SYMBOLS = YES; - DEBUG_INFORMATION_FORMAT = dwarf; - DEVELOPMENT_TEAM = 783T66X79Y; - GCC_GENERATE_DEBUGGING_SYMBOLS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - OTHER_CFLAGS = ""; - OTHER_LDFLAGS = ""; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - C87C345F1F36352600DB85FE /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEVELOPMENT_TEAM = 783T66X79Y; - OTHER_CFLAGS = ""; - OTHER_LDFLAGS = ""; - PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1255,12 +994,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -1316,12 +1057,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -1375,10 +1118,12 @@ INFOPLIST_FILE = Sources/RxDataSources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MACH_O_TYPE = staticlib; PRODUCT_BUNDLE_IDENTIFIER = kzaher.RxDataSources; PRODUCT_NAME = RxDataSources; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1398,11 +1143,13 @@ INFOPLIST_FILE = Sources/RxDataSources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MACH_O_TYPE = staticlib; PRODUCT_BUNDLE_IDENTIFIER = kzaher.RxDataSources; PRODUCT_NAME = RxDataSources; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1421,6 +1168,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = kzaher.Example; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1441,6 +1189,7 @@ PRODUCT_BUNDLE_IDENTIFIER = kzaher.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -1453,6 +1202,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = kzaher.ExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Example; USES_XCTRUNNER = YES; }; @@ -1467,6 +1217,7 @@ PRODUCT_BUNDLE_IDENTIFIER = kzaher.ExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Example; USES_XCTRUNNER = YES; }; @@ -1493,15 +1244,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - C87C345D1F36352600DB85FE /* Build configuration list for PBXLegacyTarget "Dependencies" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - C87C345E1F36352600DB85FE /* Debug */, - C87C345F1F36352600DB85FE /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; C8984C541C36AF35001E4272 /* Build configuration list for PBXProject "Example" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/Examples/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme b/Examples/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme index 73fdd3e9..e39c5c88 100644 --- a/Examples/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme +++ b/Examples/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme @@ -1,6 +1,6 @@ ( - configureCell: { ds, tv, ip, item in + configureCell: { ds, tv, _, item in let cell = tv.dequeueReusableCell(withIdentifier: "Cell") ?? UITableViewCell(style: .default, reuseIdentifier: "Cell") cell.textLabel?.text = "Item \(item)" @@ -83,7 +83,7 @@ extension CustomizationUsingTableViewDelegate : UITableViewDelegate { // you can also fetch item guard let item = dataSource?[indexPath], // .. or section and customize what you like - let _ = dataSource?[indexPath.section] + dataSource?[indexPath.section] != nil else { return 0.0 } diff --git a/Examples/Example/Example2_RandomizedSectionsAnimation.swift b/Examples/Example/Example2_RandomizedSectionsAnimation.swift index 4951c30c..1eb6d0e2 100644 --- a/Examples/Example/Example2_RandomizedSectionsAnimation.swift +++ b/Examples/Example/Example2_RandomizedSectionsAnimation.swift @@ -13,19 +13,27 @@ import RxCocoa import CoreLocation class NumberCell : UICollectionViewCell { - @IBOutlet var value: UILabel? + @IBOutlet private var value: UILabel? + + func configure(with value: String) { + self.value?.text = value + } } class NumberSectionView : UICollectionReusableView { - @IBOutlet weak var value: UILabel? + @IBOutlet private weak var value: UILabel? + + func configure(value: String) { + self.value?.text = value + } } class PartialUpdatesViewController: UIViewController { - @IBOutlet weak var animatedTableView: UITableView! - @IBOutlet weak var tableView: UITableView! - @IBOutlet weak var animatedCollectionView: UICollectionView! - @IBOutlet weak var refreshButton: UIButton! + @IBOutlet private weak var animatedTableView: UITableView! + @IBOutlet private weak var tableView: UITableView! + @IBOutlet private weak var animatedCollectionView: UICollectionView! + @IBOutlet private weak var refreshButton: UIButton! let disposeBag = DisposeBag() @@ -34,7 +42,7 @@ class PartialUpdatesViewController: UIViewController { let initialRandomizedSections = Randomizer(rng: PseudoRandomGenerator(4, 3), sections: initialValue()) - let ticks = Observable.interval(1, scheduler: MainScheduler.instance).map { _ in () } + let ticks = Observable.interval(.seconds(1), scheduler: MainScheduler.instance).map { _ in () } let randomSections = Observable.of(ticks, refreshButton.rx.tap.asObservable()) .merge() .scan(initialRandomizedSections) { a, _ in @@ -96,12 +104,12 @@ extension PartialUpdatesViewController { TableViewSectionedDataSource.TitleForHeaderInSection ) { return ( - { (_, tv, ip, i) in + { _, tv, ip, i in let cell = tv.dequeueReusableCell(withIdentifier: "Cell") ?? UITableViewCell(style:.default, reuseIdentifier: "Cell") cell.textLabel!.text = "\(i)" return cell }, - { (ds, section) -> String? in + { ds, section -> String? in return ds[section].header } ) @@ -112,15 +120,15 @@ extension PartialUpdatesViewController { CollectionViewSectionedDataSource.ConfigureSupplementaryView ) { return ( - { (_, cv, ip, i) in + { _, cv, ip, i in let cell = cv.dequeueReusableCell(withReuseIdentifier: "Cell", for: ip) as! NumberCell - cell.value!.text = "\(i)" + cell.configure(with: "\(i)") return cell }, - { (ds ,cv, kind, ip) in + { ds ,cv, kind, ip in let section = cv.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Section", for: ip) as! NumberSectionView - section.value!.text = "\(ds[ip.section].header)" + section.configure(value: "\(ds[ip.section].header)") return section } ) diff --git a/Examples/Example/Example3_TableViewEditing.swift b/Examples/Example/Example3_TableViewEditing.swift index ef89cb9b..db4d45c5 100644 --- a/Examples/Example/Example3_TableViewEditing.swift +++ b/Examples/Example/Example3_TableViewEditing.swift @@ -14,9 +14,9 @@ import RxCocoa // redux like editing example class EditingExampleViewController: UIViewController { - @IBOutlet weak var addButton: UIBarButtonItem! + @IBOutlet private weak var addButton: UIBarButtonItem! - @IBOutlet weak var tableView: UITableView! + @IBOutlet private weak var tableView: UITableView! let disposeBag = DisposeBag() override func viewDidLoad() { @@ -66,12 +66,12 @@ extension EditingExampleViewController { animationConfiguration: AnimationConfiguration(insertAnimation: .top, reloadAnimation: .fade, deleteAnimation: .left), - configureCell: { (dataSource, table, idxPath, item) in + configureCell: { _, table, idxPath, item in let cell = table.dequeueReusableCell(withIdentifier: "Cell", for: idxPath) cell.textLabel?.text = "\(item)" return cell }, - titleForHeaderInSection: { (ds, section) -> String? in + titleForHeaderInSection: { ds, section -> String? in return ds[section].header }, canEditRowAtIndexPath: { _, _ in @@ -139,9 +139,11 @@ struct SectionedTableViewState { } extension TableViewEditingCommand { + static var nextNumber = 0 static func addRandomItem() -> TableViewEditingCommand { - let randSection = Int(arc4random_uniform(UInt32(3))) - let number = Int(arc4random_uniform(UInt32(100))) + let randSection = Int.random(in: 0...2) + let number = nextNumber + defer { nextNumber = nextNumber + 1 } let item = IntItem(number: number, date: Date()) return TableViewEditingCommand.AppendItem(item: item, section: randSection) } diff --git a/Examples/Example/Example4_DifferentSectionAndItemTypes.swift b/Examples/Example/Example4_DifferentSectionAndItemTypes.swift index bcec6620..8946d9fa 100644 --- a/Examples/Example/Example4_DifferentSectionAndItemTypes.swift +++ b/Examples/Example/Example4_DifferentSectionAndItemTypes.swift @@ -15,7 +15,7 @@ import Differentiator // the trick is to just use enum for different section types class MultipleSectionModelViewController: UIViewController { - @IBOutlet weak var tableView: UITableView! + @IBOutlet private weak var tableView: UITableView! let disposeBag = DisposeBag() override func viewDidLoad() { @@ -41,24 +41,19 @@ class MultipleSectionModelViewController: UIViewController { extension MultipleSectionModelViewController { static func dataSource() -> RxTableViewSectionedReloadDataSource { return RxTableViewSectionedReloadDataSource( - configureCell: { (dataSource, table, idxPath, _) in + configureCell: { dataSource, table, idxPath, _ in switch dataSource[idxPath] { case let .ImageSectionItem(image, title): let cell: ImageTitleTableViewCell = table.dequeueReusableCell(forIndexPath: idxPath) - cell.titleLabel.text = title - cell.cellImageView.image = image - + cell.configure(image: image, title: title) return cell case let .StepperSectionItem(title): let cell: TitleSteperTableViewCell = table.dequeueReusableCell(forIndexPath: idxPath) - cell.titleLabel.text = title - + cell.configure(title: title) return cell case let .ToggleableSectionItem(title, enabled): let cell: TitleSwitchTableViewCell = table.dequeueReusableCell(forIndexPath: idxPath) - cell.switchControl.isOn = enabled - cell.titleLabel.text = title - + cell.configure(title: title, isEnabled: enabled) return cell } }, @@ -88,11 +83,11 @@ extension MultipleSectionModel: SectionModelType { var items: [SectionItem] { switch self { case .ImageProvidableSection(title: _, items: let items): - return items.map {$0} + return items.map { $0 } case .StepperableSection(title: _, items: let items): - return items.map {$0} + return items.map { $0 } case .ToggleableSection(title: _, items: let items): - return items.map {$0} + return items.map { $0 } } } diff --git a/Examples/Example/Example5_UIPickerView.swift b/Examples/Example/Example5_UIPickerView.swift index 7f964510..2e19a28c 100644 --- a/Examples/Example/Example5_UIPickerView.swift +++ b/Examples/Example/Example5_UIPickerView.swift @@ -13,41 +13,49 @@ import RxDataSources final class ReactivePickerViewControllerExample: UIViewController { - @IBOutlet weak var firstPickerView: UIPickerView! - @IBOutlet weak var secondPickerView: UIPickerView! - @IBOutlet weak var thirdPickerView: UIPickerView! + @IBOutlet private weak var firstPickerView: UIPickerView! + @IBOutlet private weak var secondPickerView: UIPickerView! + @IBOutlet private weak var thirdPickerView: UIPickerView! let disposeBag = DisposeBag() private let stringPickerAdapter = RxPickerViewStringAdapter<[String]>(components: [], numberOfComponents: { _,_,_ in 1 }, - numberOfRowsInComponent: { (_, _, items, _) -> Int in + numberOfRowsInComponent: { _, _, items, _ -> Int in return items.count }, - titleForRow: { (_, _, items, row, _) -> String? in + titleForRow: { _, _, items, row, _ -> String? in return items[row] }) - private let attributedStringPickerAdapter = RxPickerViewAttributedStringAdapter<[String]>(components: [], - numberOfComponents: { _,_,_ in 1 }, - numberOfRowsInComponent: { (_, _, items, _) -> Int in - return items.count - }) { (_, _, items, row, _) -> NSAttributedString? in - return NSAttributedString(string: items[row], - attributes: [ - NSAttributedStringKey.foregroundColor: UIColor.purple, - NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleDouble.rawValue, - NSAttributedStringKey.textEffect: NSAttributedString.TextEffectStyle.letterpressStyle - ]) - } - private let viewPickerAdapter = RxPickerViewViewAdapter<[String]>(components: [], - numberOfComponents: { _,_,_ in 1 }, - numberOfRowsInComponent: { (_, _, items, _) -> Int in - return items.count - }) { (_, _, _, row, _, view) -> UIView in - let componentView = view ?? UIView() - componentView.backgroundColor = row % 2 == 0 ? UIColor.red : UIColor.blue - return componentView - } + private let attributedStringPickerAdapter = RxPickerViewAttributedStringAdapter<[String]>( + components: [], + numberOfComponents: { _,_,_ in 1 }, + numberOfRowsInComponent: { _, _, items, _ -> Int in + return items.count + }, + attributedTitleForRow: { _, _, items, row, _ -> NSAttributedString? in + NSAttributedString( + string: items[row], + attributes: [ + .foregroundColor: UIColor.purple, + .underlineStyle: NSUnderlineStyle.double.rawValue, + .textEffect: NSAttributedString.TextEffectStyle.letterpressStyle + ] + ) + } + ) + private let viewPickerAdapter = RxPickerViewViewAdapter<[String]>( + components: [], + numberOfComponents: { _,_,_ in 1 }, + numberOfRowsInComponent: { _, _, items, _ -> Int in + return items.count + }, + viewForRow: { _, _, _, row, _, view -> UIView in + let componentView = view ?? UIView() + componentView.backgroundColor = row % 2 == 0 ? UIColor.red : UIColor.blue + return componentView + } + ) override func viewDidLoad() { super.viewDidLoad() diff --git a/Examples/Example/Support/AppDelegate.swift b/Examples/Example/Support/AppDelegate.swift index c817dce6..ae6c792f 100644 --- a/Examples/Example/Support/AppDelegate.swift +++ b/Examples/Example/Support/AppDelegate.swift @@ -13,9 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { - // Override point for customization after application launch. + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { return true } diff --git a/Examples/Example/Views/ImageTitleTableViewCell.swift b/Examples/Example/Views/ImageTitleTableViewCell.swift index a5ec3689..c47bd1a9 100644 --- a/Examples/Example/Views/ImageTitleTableViewCell.swift +++ b/Examples/Example/Views/ImageTitleTableViewCell.swift @@ -10,6 +10,11 @@ import UIKit class ImageTitleTableViewCell: UITableViewCell { - @IBOutlet weak var cellImageView: UIImageView! - @IBOutlet weak var titleLabel: UILabel! + @IBOutlet private weak var cellImageView: UIImageView! + @IBOutlet private weak var titleLabel: UILabel! + + func configure(image: UIImage, title: String) { + cellImageView.image = image + titleLabel.text = title + } } diff --git a/Examples/Example/Views/TitleSteperTableViewCell.swift b/Examples/Example/Views/TitleSteperTableViewCell.swift index 2168849e..98fea00b 100644 --- a/Examples/Example/Views/TitleSteperTableViewCell.swift +++ b/Examples/Example/Views/TitleSteperTableViewCell.swift @@ -10,17 +10,11 @@ import UIKit class TitleSteperTableViewCell: UITableViewCell { - @IBOutlet weak var stepper: UIStepper! - @IBOutlet weak var titleLabel: UILabel! - override func awakeFromNib() { - super.awakeFromNib() - // Initialization code - } - - override func setSelected(_ selected: Bool, animated: Bool) { - super.setSelected(selected, animated: animated) + @IBOutlet private weak var stepper: UIStepper! + @IBOutlet private weak var titleLabel: UILabel! - // Configure the view for the selected state + func configure(title: String) { + titleLabel.text = title } } diff --git a/Examples/Example/Views/TitleSwitchTableViewCell.swift b/Examples/Example/Views/TitleSwitchTableViewCell.swift index 8ae8734d..92952355 100644 --- a/Examples/Example/Views/TitleSwitchTableViewCell.swift +++ b/Examples/Example/Views/TitleSwitchTableViewCell.swift @@ -11,6 +11,11 @@ import UIKit class TitleSwitchTableViewCell: UITableViewCell { - @IBOutlet weak var switchControl: UISwitch! - @IBOutlet weak var titleLabel: UILabel! + @IBOutlet private weak var switchControl: UISwitch! + @IBOutlet private weak var titleLabel: UILabel! + + func configure(title: String, isEnabled: Bool) { + switchControl.isOn = isEnabled + titleLabel.text = title + } } diff --git a/Examples/Example/Views/UIKitExtensions.swift b/Examples/Example/Views/UIKitExtensions.swift index 5936b526..03263ec6 100644 --- a/Examples/Example/Views/UIKitExtensions.swift +++ b/Examples/Example/Views/UIKitExtensions.swift @@ -11,7 +11,7 @@ import class UIKit.UITableView import struct Foundation.IndexPath protocol ReusableView: class { - static var reuseIdentifier: String {get} + static var reuseIdentifier: String { get } } extension ReusableView { diff --git a/Examples/RxSwift b/Examples/RxSwift deleted file mode 160000 index d158e770..00000000 --- a/Examples/RxSwift +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d158e7700655114e990313948d2de561d50e1115 diff --git a/Examples/RxSwift b/Examples/RxSwift new file mode 120000 index 00000000..65f86486 --- /dev/null +++ b/Examples/RxSwift @@ -0,0 +1 @@ +../Carthage/Checkouts/RxSwift \ No newline at end of file diff --git a/Examples/dependencies.sh b/Examples/dependencies.sh deleted file mode 100755 index ae64e8eb..00000000 --- a/Examples/dependencies.sh +++ /dev/null @@ -1,6 +0,0 @@ -set -e -if [[ ( ! -d "RxSwift/.git" ) ]]; then - git submodule update --init --recursive --force - cd RxSwift - git reset origin/master --hard -fi diff --git a/Package.resolved b/Package.resolved index b77b1084..c6207994 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/ReactiveX/RxSwift.git", "state": { "branch": null, - "revision": "12cccb171ad9038251af6883807f0290c1d75a5b", - "version": "4.0.0" + "revision": "c8742ed97fc2f0c015a5ea5eddefb064cd7532d2", + "version": "6.0.0" } } ] diff --git a/Package.swift b/Package.swift index 99be0b88..93ec31a5 100644 --- a/Package.swift +++ b/Package.swift @@ -1,19 +1,24 @@ -// swift-tools-version:4.0 +// swift-tools-version:5.1 import PackageDescription let package = Package( name: "RxDataSources", + platforms: [ + .iOS(.v9), .tvOS(.v9) + ], products: [ .library(name: "RxDataSources", targets: ["RxDataSources"]), - .library(name: "Differentiator", targets: ["Differentiator"]), + .library(name: "RxDataSources-Dynamic", type: .dynamic, targets: ["RxDataSources"]), + .library(name: "Differentiator", targets: ["Differentiator"]) ], dependencies: [ - .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "4.0.0")), + .package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.0.0")) ], targets: [ .target(name: "RxDataSources", dependencies: ["Differentiator", "RxSwift", "RxCocoa"]), .target(name: "Differentiator"), - .testTarget(name: "RxDataSourcesTests", dependencies: ["RxDataSources"]), - ] + .testTarget(name: "RxDataSourcesTests", dependencies: ["RxDataSources"]) + ], + swiftLanguageVersions: [.v5] ) diff --git a/README.md b/README.md index 88891b62..408ec8d7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Travis CI](https://travis-ci.org/RxSwiftCommunity/RxDataSources.svg?branch=master)](https://travis-ci.org/RxSwiftCommunity/RxDataSources) +[![Travis CI](https://travis-ci.org/RxSwiftCommunity/RxDataSources.svg?branch=main)](https://travis-ci.org/RxSwiftCommunity/RxDataSources) Table and Collection view data sources ====================================== @@ -105,7 +105,7 @@ dataSource.titleForHeaderInSection = { dataSource, index in return dataSource.sectionModels[index].header } -dataSource.titleForFooterInSection = { dataSource, indexPath in +dataSource.titleForFooterInSection = { dataSource, index in return dataSource.sectionModels[index].footer } @@ -143,10 +143,11 @@ To use one of the two animated data sources, you must take a few extra steps on ## Requirements -Xcode 9.0 +Xcode 10.2 -Swift 4.0 +Swift 5.0 +For Swift 4.x version please use versions `3.0.0 ... 3.1.0` For Swift 3.x version please use versions `1.0 ... 2.0.2` For Swift 2.3 version please use versions `0.1 ... 0.9` @@ -158,12 +159,29 @@ For Swift 2.3 version please use versions `0.1 ... 0.9` Podfile ``` -pod 'RxDataSources', '~> 3.0' +pod 'RxDataSources', '~> 5.0' ``` ### Carthage Cartfile ``` -github "RxSwiftCommunity/RxDataSources" ~> 3.0 +github "RxSwiftCommunity/RxDataSources" ~> 5.0 ``` + +### Swift Package Manager + +Create a `Package.swift` file. + +```swift +import PackageDescription + +let package = Package( + name: "SampleProject", + dependencies: [ + .package(url: "https://github.com/RxSwiftCommunity/RxDataSources.git", from: "5.0.0") + ] +) +``` + +If you are using Xcode 11 or higher, go to **File / Swift Packages / Add Package Dependency...** and enter package repository URL **https://github.com/RxSwiftCommunity/RxDataSources.git**, then follow the instructions. diff --git a/RxDataSources.podspec b/RxDataSources.podspec index db43dfe7..e0107853 100644 --- a/RxDataSources.podspec +++ b/RxDataSources.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "RxDataSources" - s.version = "3.1.0" + s.version = "5.0.0" s.summary = "This is a collection of reactive data sources for UITableView and UICollectionView." s.description = <<-DESC This is a collection of reactive data sources for UITableView and UICollectionView. @@ -34,13 +34,14 @@ data s.source = { :git => "https://github.com/RxSwiftCommunity/RxDataSources.git", :tag => s.version.to_s } s.requires_arc = true - + s.swift_version = '5.0' + s.source_files = 'Sources/RxDataSources/**/*.swift' - s.dependency 'Differentiator', '~> 3.0' - s.dependency 'RxSwift', '~> 4.0' - s.dependency 'RxCocoa', '~> 4.0' + s.dependency 'Differentiator', '~> 5.0' + s.dependency 'RxSwift', '~> 6.0' + s.dependency 'RxCocoa', '~> 6.0' - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '9.0' s.tvos.deployment_target = '9.0' end diff --git a/RxDataSources.xcodeproj/project.pbxproj b/RxDataSources.xcodeproj/project.pbxproj index abe2ca36..2e84b80b 100644 --- a/RxDataSources.xcodeproj/project.pbxproj +++ b/RxDataSources.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -15,6 +15,10 @@ 03EEEE961F5B7D71006068BC /* Randomizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EEEE851F5B7D5C006068BC /* Randomizer.swift */; }; 03EEEE971F5B7D71006068BC /* s.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EEEE861F5B7D5C006068BC /* s.swift */; }; 03EEEE981F5B7D71006068BC /* XCTest+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EEEE871F5B7D5C006068BC /* XCTest+Extensions.swift */; }; + 70C0622425A8FE3D002A57ED /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80FB1F48228489EC009D6516 /* RxSwift.framework */; platformFilter = ios; }; + 70C0623425A8FE54002A57ED /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80FB1F4A228489EC009D6516 /* RxCocoa.framework */; platformFilter = ios; }; + 70C0622425A8FE3D002A57ED /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80FB1F48228489EC009D6516 /* RxSwift.framework */; }; + 70C0623425A8FE54002A57ED /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 80FB1F4A228489EC009D6516 /* RxCocoa.framework */; }; C81FBF461F3B9CED0094061E /* Differentiator.podspec in Resources */ = {isa = PBXBuildFile; fileRef = C81FBF451F3B9CED0094061E /* Differentiator.podspec */; }; C81FBF5E1F3B9D660094061E /* Array+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C81FBF5B1F3B9D4C0094061E /* Array+Extensions.swift */; }; C81FBF601F3B9D8B0094061E /* FloatingPointType+IdentifiableType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C81FBF5F1F3B9D8B0094061E /* FloatingPointType+IdentifiableType.swift */; }; @@ -52,6 +56,76 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 80FB1F47228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C8A56AD71AD7424700B4673B; + remoteInfo = RxSwift; + }; + 80FB1F49228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C809396D1B8A71760088E94D; + remoteInfo = RxCocoa; + }; + 80FB1F4B228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = A2897D53225CA1E7004EA481; + remoteInfo = RxRelay; + }; + 80FB1F4D228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C8093BC71B8A71F00088E94D; + remoteInfo = RxBlocking; + }; + 80FB1F4F228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C88FA50C1C25C44800CCFEA4; + remoteInfo = RxTest; + }; + 80FB1F51228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C83508C31C386F6F0027C24C; + remoteInfo = "AllTests-iOS"; + }; + 80FB1F53228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C83509841C38740E0027C24C; + remoteInfo = "AllTests-tvOS"; + }; + 80FB1F55228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C83509941C38742C0027C24C; + remoteInfo = "AllTests-macOS"; + }; + 80FB1F57228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C85BA04B1C3878740075D68E; + remoteInfo = Microoptimizations; + }; + 80FB1F59228489EC009D6516 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C8E8BA551E2C181A00A4AC2C; + remoteInfo = Benchmarks; + }; C82C3C9A1F3B93D200309AE8 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C8984C511C36AF35001E4272 /* Project object */; @@ -71,6 +145,8 @@ 03EEEE851F5B7D5C006068BC /* Randomizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Randomizer.swift; sourceTree = ""; }; 03EEEE861F5B7D5C006068BC /* s.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = s.swift; sourceTree = ""; }; 03EEEE871F5B7D5C006068BC /* XCTest+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "XCTest+Extensions.swift"; sourceTree = ""; }; + 1E38DA4A22778D1A00C07A09 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; + 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Rx.xcodeproj; path = Carthage/Checkouts/RxSwift/Rx.xcodeproj; sourceTree = ""; }; C81905AE1DEA019100AE679C /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; C81FBF451F3B9CED0094061E /* Differentiator.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Differentiator.podspec; sourceTree = ""; }; C81FBF5B1F3B9D4C0094061E /* Array+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Extensions.swift"; sourceTree = ""; }; @@ -132,6 +208,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 70C0623425A8FE54002A57ED /* RxCocoa.framework in Frameworks */, + 70C0622425A8FE3D002A57ED /* RxSwift.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -163,6 +241,30 @@ path = RxDataSourcesTests; sourceTree = ""; }; + 80FB1F3B228489EB009D6516 /* Products */ = { + isa = PBXGroup; + children = ( + 80FB1F48228489EC009D6516 /* RxSwift.framework */, + 80FB1F4A228489EC009D6516 /* RxCocoa.framework */, + 80FB1F4C228489EC009D6516 /* RxRelay.framework */, + 80FB1F4E228489EC009D6516 /* RxBlocking.framework */, + 80FB1F50228489EC009D6516 /* RxTest.framework */, + 80FB1F52228489EC009D6516 /* AllTests-iOS.xctest */, + 80FB1F54228489EC009D6516 /* AllTests-tvOS.xctest */, + 80FB1F56228489EC009D6516 /* AllTests-macOS.xctest */, + 80FB1F58228489EC009D6516 /* PerformanceTests.app */, + 80FB1F5A228489EC009D6516 /* Benchmarks.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 80FB1F5B228489FF009D6516 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; C81FBF5A1F3B9CF10094061E /* Podspecs */ = { isa = PBXGroup; children = ( @@ -205,11 +307,14 @@ C8984C501C36AF35001E4272 = { isa = PBXGroup; children = ( + 1E38DA4A22778D1A00C07A09 /* Package.swift */, C8B438561F3BA49F00B6A80B /* CHANGELOG.md */, C81FBF5A1F3B9CF10094061E /* Podspecs */, C85EE5461C36F1FC0090614D /* Sources */, 03EEEE7D1F5B7D5C006068BC /* Tests */, C8984C5B1C36AF35001E4272 /* Products */, + 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */, + 80FB1F5B228489FF009D6516 /* Frameworks */, ); sourceTree = ""; }; @@ -309,6 +414,7 @@ isa = PBXNativeTarget; buildConfigurationList = C8984C621C36AF35001E4272 /* Build configuration list for PBXNativeTarget "RxDataSources" */; buildPhases = ( + 783D0B9C22A83BC600B15646 /* Swiftlint */, C8984C551C36AF35001E4272 /* Sources */, C8984C561C36AF35001E4272 /* Frameworks */, C8984C571C36AF35001E4272 /* Headers */, @@ -320,6 +426,8 @@ C82C3C9B1F3B93D200309AE8 /* PBXTargetDependency */, ); name = RxDataSources; + packageProductDependencies = ( + ); productName = RxDataSources; productReference = C8984C5A1C36AF35001E4272 /* RxDataSources.framework */; productType = "com.apple.product-type.framework"; @@ -331,7 +439,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0810; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1230; ORGANIZATIONNAME = kzaher; TargetAttributes = { C81905AD1DEA019100AE679C = { @@ -350,15 +458,23 @@ }; buildConfigurationList = C8984C541C36AF35001E4272 /* Build configuration list for PBXProject "RxDataSources" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, Base, ); mainGroup = C8984C501C36AF35001E4272; + packageReferences = ( + ); productRefGroup = C8984C5B1C36AF35001E4272 /* Products */; projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 80FB1F3B228489EB009D6516 /* Products */; + ProjectRef = 80FB1F3A228489EB009D6516 /* Rx.xcodeproj */; + }, + ); projectRoot = ""; targets = ( C8984C591C36AF35001E4272 /* RxDataSources */, @@ -368,6 +484,80 @@ }; /* End PBXProject section */ +/* Begin PBXReferenceProxy section */ + 80FB1F48228489EC009D6516 /* RxSwift.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = RxSwift.framework; + remoteRef = 80FB1F47228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F4A228489EC009D6516 /* RxCocoa.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = RxCocoa.framework; + remoteRef = 80FB1F49228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F4C228489EC009D6516 /* RxRelay.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = RxRelay.framework; + remoteRef = 80FB1F4B228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F4E228489EC009D6516 /* RxBlocking.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = RxBlocking.framework; + remoteRef = 80FB1F4D228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F50228489EC009D6516 /* RxTest.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = RxTest.framework; + remoteRef = 80FB1F4F228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F52228489EC009D6516 /* AllTests-iOS.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "AllTests-iOS.xctest"; + remoteRef = 80FB1F51228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F54228489EC009D6516 /* AllTests-tvOS.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "AllTests-tvOS.xctest"; + remoteRef = 80FB1F53228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F56228489EC009D6516 /* AllTests-macOS.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "AllTests-macOS.xctest"; + remoteRef = 80FB1F55228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F58228489EC009D6516 /* PerformanceTests.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + name = PerformanceTests.app; + path = Microoptimizations.app; + remoteRef = 80FB1F57228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 80FB1F5A228489EC009D6516 /* Benchmarks.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = Benchmarks.xctest; + remoteRef = 80FB1F59228489EC009D6516 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + /* Begin PBXResourcesBuildPhase section */ C81905AC1DEA019100AE679C /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -394,6 +584,27 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 783D0B9C22A83BC600B15646 /* Swiftlint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = Swiftlint; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"SwiftLint does not exist, download from https://github.com/realm/SwiftLint\"\nfi\n\n"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ C81905AA1DEA019100AE679C /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -473,8 +684,12 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; DEVELOPMENT_TEAM = 783T66X79Y; INFOPLIST_FILE = Tests/RxDataSourcesTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = io.rx.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; @@ -490,11 +705,16 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; DEVELOPMENT_TEAM = 783T66X79Y; INFOPLIST_FILE = Tests/RxDataSourcesTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = io.rx.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; }; name = Release; }; @@ -512,7 +732,11 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Differentiator/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = org.rxswiftcommunity.Differentiator; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -535,12 +759,17 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/Differentiator/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = org.rxswiftcommunity.Differentiator; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; }; name = Release; }; @@ -556,14 +785,17 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -575,22 +807,10 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; - "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/tvOS", - ); - "FRAMEWORK_SEARCH_PATHS[sdk=appletvsimulator*]" = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/tvOS", - ); - "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - "FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); + "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "$(inherited)"; + "FRAMEWORK_SEARCH_PATHS[sdk=appletvsimulator*]" = "$(inherited)"; + "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = "$(inherited)"; + "FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(inherited)"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -605,18 +825,18 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - "LD_RUNPATH_SEARCH_PATHS[sdk=appletvos*]" = "$(inherited) $(PROJECT_DIR)/Carthage/Build/tvOS"; - "LD_RUNPATH_SEARCH_PATHS[sdk=appletvsimulator*]" = "$(inherited) $(PROJECT_DIR)/Carthage/Build/tvOS"; - "LD_RUNPATH_SEARCH_PATHS[sdk=iphoneos*]" = "$(inherited) $(PROJECT_DIR)/Carthage/Build/iOS"; - "LD_RUNPATH_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(inherited) $(PROJECT_DIR)/Carthage/Build/iOS"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + "LD_RUNPATH_SEARCH_PATHS[sdk=appletvos*]" = "$(inherited)"; + "LD_RUNPATH_SEARCH_PATHS[sdk=appletvsimulator*]" = "$(inherited)"; + "LD_RUNPATH_SEARCH_PATHS[sdk=iphoneos*]" = "$(inherited)"; + "LD_RUNPATH_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(inherited)"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; OTHER_SWIFT_FLAGS = "-D DEBUG"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -637,14 +857,17 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -656,22 +879,10 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; - "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/tvOS", - ); - "FRAMEWORK_SEARCH_PATHS[sdk=appletvsimulator*]" = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/tvOS", - ); - "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - "FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); + "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "$(inherited)"; + "FRAMEWORK_SEARCH_PATHS[sdk=appletvsimulator*]" = "$(inherited)"; + "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = "$(inherited)"; + "FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(inherited)"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -680,17 +891,18 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - "LD_RUNPATH_SEARCH_PATHS[sdk=appletvos*]" = "$(inherited) $(PROJECT_DIR)/Carthage/Build/tvOS"; - "LD_RUNPATH_SEARCH_PATHS[sdk=appletvsimulator*]" = "$(inherited) $(PROJECT_DIR)/Carthage/Build/tvOS"; - "LD_RUNPATH_SEARCH_PATHS[sdk=iphoneos*]" = "$(inherited) $(PROJECT_DIR)/Carthage/Build/iOS"; - "LD_RUNPATH_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(inherited) $(PROJECT_DIR)/Carthage/Build/iOS"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + "LD_RUNPATH_SEARCH_PATHS[sdk=appletvos*]" = "$(inherited)"; + "LD_RUNPATH_SEARCH_PATHS[sdk=appletvsimulator*]" = "$(inherited)"; + "LD_RUNPATH_SEARCH_PATHS[sdk=iphoneos*]" = "$(inherited)"; + "LD_RUNPATH_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(inherited)"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; OTHER_SWIFT_FLAGS = ""; SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.0; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; @@ -711,7 +923,11 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/RxDataSources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = kzaher.RxDataSources; PRODUCT_NAME = RxDataSources; SKIP_INSTALL = YES; @@ -730,12 +946,17 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/RxDataSources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = kzaher.RxDataSources; PRODUCT_NAME = RxDataSources; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator"; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; }; name = Release; }; diff --git a/RxDataSources.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/RxDataSources.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 9e63a231..919434a6 100644 --- a/RxDataSources.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/RxDataSources.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/RxDataSources.xcodeproj/xcshareddata/xcschemes/Differentiator.xcscheme b/RxDataSources.xcodeproj/xcshareddata/xcschemes/Differentiator.xcscheme index 2fb1b155..2e091398 100644 --- a/RxDataSources.xcodeproj/xcshareddata/xcschemes/Differentiator.xcscheme +++ b/RxDataSources.xcodeproj/xcshareddata/xcschemes/Differentiator.xcscheme @@ -1,6 +1,6 @@ - - - - - - - - - - - - Bool { + return lhs.model == rhs.model + && lhs.items == rhs.items + } +} diff --git a/Sources/Differentiator/Changeset.swift b/Sources/Differentiator/Changeset.swift index b3e88a31..8eb40e90 100644 --- a/Sources/Differentiator/Changeset.swift +++ b/Sources/Differentiator/Changeset.swift @@ -8,13 +8,13 @@ import Foundation -public struct Changeset { - public typealias I = S.Item +public struct Changeset { + public typealias Item = Section.Item public let reloadData: Bool - public let originalSections: [S] - public let finalSections: [S] + public let originalSections: [Section] + public let finalSections: [Section] public let insertedSections: [Int] public let deletedSections: [Int] @@ -27,18 +27,16 @@ public struct Changeset { public let updatedItems: [ItemPath] init(reloadData: Bool = false, - originalSections: [S] = [], - finalSections: [S] = [], - insertedSections: [Int] = [], - deletedSections: [Int] = [], - movedSections: [(from: Int, to: Int)] = [], - updatedSections: [Int] = [], - - insertedItems: [ItemPath] = [], - deletedItems: [ItemPath] = [], - movedItems: [(from: ItemPath, to: ItemPath)] = [], - updatedItems: [ItemPath] = [] - ) { + originalSections: [Section] = [], + finalSections: [Section] = [], + insertedSections: [Int] = [], + deletedSections: [Int] = [], + movedSections: [(from: Int, to: Int)] = [], + updatedSections: [Int] = [], + insertedItems: [ItemPath] = [], + deletedItems: [ItemPath] = [], + movedItems: [(from: ItemPath, to: ItemPath)] = [], + updatedItems: [ItemPath] = []) { self.reloadData = reloadData self.originalSections = originalSections @@ -55,8 +53,8 @@ public struct Changeset { self.updatedItems = updatedItems } - public static func initialValue(_ sections: [S]) -> Changeset { - return Changeset( + public static func initialValue(_ sections: [Section]) -> Changeset
{ + return Changeset
( reloadData: true, finalSections: sections, insertedSections: Array(0 ..< sections.count) as [Int] diff --git a/Sources/Differentiator/Diff.swift b/Sources/Differentiator/Diff.swift index b1ff3948..7e4b8712 100644 --- a/Sources/Differentiator/Diff.swift +++ b/Sources/Differentiator/Diff.swift @@ -50,23 +50,21 @@ public enum Diff { case untouched var debugDescription: String { - get { - switch self { - case .inserted: - return "Inserted" - case .insertedAutomatically: - return "InsertedAutomatically" - case .deleted: - return "Deleted" - case .deletedAutomatically: - return "DeletedAutomatically" - case .moved: - return "Moved" - case .movedAutomatically: - return "MovedAutomatically" - case .untouched: - return "Untouched" - } + switch self { + case .inserted: + return "Inserted" + case .insertedAutomatically: + return "InsertedAutomatically" + case .deleted: + return "Deleted" + case .deletedAutomatically: + return "DeletedAutomatically" + case .moved: + return "Moved" + case .movedAutomatically: + return "MovedAutomatically" + case .untouched: + return "Untouched" } } } @@ -78,9 +76,7 @@ public enum Diff { var itemCount: Int var debugDescription: String { - get { - return "\(event), \(String(describing: indexAfterDelete))" - } + return "\(event), \(String(describing: indexAfterDelete))" } static var initial: SectionAssociatedData { @@ -94,9 +90,7 @@ public enum Diff { var moveIndex: ItemPath? var debugDescription: String { - get { - return "\(event) \(String(describing: indexAfterDelete))" - } + return "\(event) \(String(describing: indexAfterDelete))" } static var initial : ItemAssociatedData { @@ -104,8 +98,8 @@ public enum Diff { } } - private static func indexSections(_ sections: [S]) throws -> [S.Identity : Int] { - var indexedSections: [S.Identity : Int] = [:] + private static func indexSections(_ sections: [Section]) throws -> [Section.Identity : Int] { + var indexedSections: [Section.Identity : Int] = [:] for (i, section) in sections.enumerated() { guard indexedSections[section.identity] == nil else { #if DEBUG @@ -126,17 +120,21 @@ public enum Diff { //================================================================================ // swift dictionary optimizations { - private struct OptimizedIdentity : Hashable { + private struct OptimizedIdentity : Hashable { - let hashValue: Int - let identity: UnsafePointer + let identity: UnsafePointer + private let cachedHashValue: Int - init(_ identity: UnsafePointer) { + init(_ identity: UnsafePointer) { self.identity = identity - self.hashValue = identity.pointee.hashValue + self.cachedHashValue = identity.pointee.hashValue } - static func == (lhs: OptimizedIdentity, rhs: OptimizedIdentity) -> Bool { + func hash(into hasher: inout Hasher) { + hasher.combine(self.cachedHashValue) + } + + static func == (lhs: OptimizedIdentity, rhs: OptimizedIdentity) -> Bool { if lhs.hashValue != rhs.hashValue { return false } @@ -153,9 +151,9 @@ public enum Diff { private static func calculateAssociatedData( initialItemCache: ContiguousArray>, finalItemCache: ContiguousArray> - ) throws + ) throws -> (ContiguousArray>, ContiguousArray>) { - + // swiftlint:disable:next nesting typealias Identity = Item.Identity let totalInitialItems = initialItemCache.map { $0.count }.reduce(0, +) @@ -181,7 +179,7 @@ public enum Diff { return ContiguousArray(repeating: ItemAssociatedData.initial, count: items.count) }) - try initialIdentities.withUnsafeBufferPointer { (identitiesBuffer: UnsafeBufferPointer) -> () in + try initialIdentities.withUnsafeBufferPointer { (identitiesBuffer: UnsafeBufferPointer) -> Void in var dictionary: [OptimizedIdentity: Int] = Dictionary(minimumCapacity: totalInitialItems * 2) for i in 0 ..< initialIdentities.count { @@ -350,15 +348,13 @@ public enum Diff { // // There maybe exists a better division, but time will tell. // - public static func differencesForSectionedView( - initialSections: [S], - finalSections: [S]) - throws -> [Changeset] { - typealias I = S.Item - - var result: [Changeset] = [] + public static func differencesForSectionedView( + initialSections: [Section], + finalSections: [Section]) + throws -> [Changeset
] { + var result: [Changeset
] = [] - var sectionCommands = try CommandGenerator.generatorForInitialSections(initialSections, finalSections: finalSections) + var sectionCommands = try CommandGenerator
.generatorForInitialSections(initialSections, finalSections: finalSections) result.append(contentsOf: try sectionCommands.generateDeleteSectionsDeletedItemsAndUpdatedItems()) result.append(contentsOf: try sectionCommands.generateInsertAndMoveSections()) @@ -367,20 +363,12 @@ public enum Diff { return result } + private struct CommandGenerator { + // swiftlint:disable:next nesting + typealias Item = Section.Item - @available(*, deprecated, renamed: "differencesForSectionedView(initialSections:finalSections:)") - public static func differencesForSectionedView( - _ initialSections: [S], - finalSections: [S]) - throws -> [Changeset] { - return try differencesForSectionedView(initialSections: initialSections, finalSections: finalSections) - } - - private struct CommandGenerator { - typealias Item = S.Item - - let initialSections: [S] - let finalSections: [S] + let initialSections: [Section] + let finalSections: [Section] let initialSectionData: ContiguousArray let finalSectionData: ContiguousArray @@ -392,9 +380,9 @@ public enum Diff { let finalItemCache: ContiguousArray> static func generatorForInitialSections( - _ initialSections: [S], - finalSections: [S] - ) throws -> CommandGenerator { + _ initialSections: [Section], + finalSections: [Section] + ) throws -> CommandGenerator
{ let (initialSectionData, finalSectionData) = try calculateSectionMovements(initialSections: initialSections, finalSections: finalSections) @@ -413,7 +401,7 @@ public enum Diff { finalSectionData: finalSectionData ) - return CommandGenerator( + return CommandGenerator
( initialSections: initialSections, finalSections: finalSections, @@ -450,7 +438,7 @@ public enum Diff { return i2 } - i2 = i2 + 1 + i2 += 1 } return nil @@ -458,7 +446,7 @@ public enum Diff { // first mark deleted items for i in 0 ..< initialItemCache.count { - guard let _ = initialSectionData[i].moveIndex else { + guard initialSectionData[i].moveIndex != nil else { continue } @@ -522,7 +510,7 @@ public enum Diff { return (initialItemData, finalItemData) } - static func calculateSectionMovements(initialSections: [S], finalSections: [S]) throws + static func calculateSectionMovements(initialSections: [Section], finalSections: [Section]) throws -> (ContiguousArray, ContiguousArray) { let initialSectionIndexes = try Diff.indexSections(initialSections) @@ -571,7 +559,7 @@ public enum Diff { return i } - i = i + 1 + i += 1 } return nil @@ -596,22 +584,20 @@ public enum Diff { } // inserted sections - for (i, section) in finalSectionData.enumerated() { - if section.moveIndex == nil { - _ = finalSectionData[i].event == .inserted - } + for (i, section) in finalSectionData.enumerated() where section.moveIndex == nil { + _ = finalSectionData[i].event == .inserted } return (initialSectionData, finalSectionData) } - mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems() throws -> [Changeset] { + mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems() throws -> [Changeset
] { var deletedSections = [Int]() var deletedItems = [ItemPath]() var updatedItems = [ItemPath]() - var afterDeleteState = [S]() + var afterDeleteState = [Section]() // mark deleted items { // 1rst stage again (I know, I know ...) @@ -626,7 +612,7 @@ public enum Diff { continue } - var afterDeleteItems: [S.Item] = [] + var afterDeleteItems: [Section.Item] = [] for j in 0 ..< initialItems.count { let event = initialItemData[i][j].event switch event { @@ -637,14 +623,16 @@ public enum Diff { let finalItem = finalItemCache[finalItemIndex.sectionIndex][finalItemIndex.itemIndex] if finalItem != initialSections[i].items[j] { updatedItems.append(ItemPath(sectionIndex: i, itemIndex: j)) + afterDeleteItems.append(finalItem) + } else { + afterDeleteItems.append(initialSections[i].items[j]) } - afterDeleteItems.append(finalItem) default: try precondition(false, "Unhandled case") } } - afterDeleteState.append(try S.init(safeOriginal: initialSections[i], safeItems: afterDeleteItems)) + afterDeleteState.append(try Section(safeOriginal: initialSections[i], safeItems: afterDeleteItems)) } // } @@ -660,7 +648,7 @@ public enum Diff { )] } - func generateInsertAndMoveSections() throws -> [Changeset] { + func generateInsertAndMoveSections() throws -> [Changeset
] { var movedSections = [(from: Int, to: Int)]() var insertedSections = [Int]() @@ -692,7 +680,7 @@ public enum Diff { } // sections should be in place, but items should be original without deleted ones - let sectionsAfterChange: [S] = try self.finalSections.enumerated().map { i, s -> S in + let sectionsAfterChange: [Section] = try self.finalSections.enumerated().map { i, s -> Section in let event = self.finalSectionData[i].event if event == .inserted { @@ -703,7 +691,7 @@ public enum Diff { let originalSectionIndex = try finalSectionData[i].moveIndex.unwrap() let originalSection = initialSections[originalSectionIndex] - var items: [S.Item] = [] + var items: [Section.Item] = [] items.reserveCapacity(originalSection.items.count) let itemAssociatedData = self.initialItemData[originalSectionIndex] for j in 0 ..< originalSection.items.count { @@ -721,7 +709,7 @@ public enum Diff { items.append(finalItemCache[finalIndex.sectionIndex][finalIndex.itemIndex]) } - let modifiedSection = try S.init(safeOriginal: s, safeItems: items) + let modifiedSection = try Section(safeOriginal: s, safeItems: items) return modifiedSection } @@ -738,7 +726,7 @@ public enum Diff { )] } - mutating func generateInsertAndMovedItems() throws -> [Changeset] { + mutating func generateInsertAndMovedItems() throws -> [Changeset
] { var insertedItems = [ItemPath]() var movedItems = [(from: ItemPath, to: ItemPath)]() diff --git a/Sources/Differentiator/Info.plist b/Sources/Differentiator/Info.plist index 9f023d2b..9a3b7072 100644 --- a/Sources/Differentiator/Info.plist +++ b/Sources/Differentiator/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.0.2 + 4.0.1 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/Sources/Differentiator/ItemPath.swift b/Sources/Differentiator/ItemPath.swift index 9551e112..0daaf710 100644 --- a/Sources/Differentiator/ItemPath.swift +++ b/Sources/Differentiator/ItemPath.swift @@ -28,8 +28,9 @@ public func == (lhs: ItemPath, rhs: ItemPath) -> Bool { extension ItemPath: Hashable { - public var hashValue: Int { - return sectionIndex.byteSwapped.hashValue ^ itemIndex.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(sectionIndex.byteSwapped.hashValue) + hasher.combine(itemIndex.hashValue) } } diff --git a/Sources/Differentiator/SectionModel.swift b/Sources/Differentiator/SectionModel.swift index 1367c2a8..28456b6e 100644 --- a/Sources/Differentiator/SectionModel.swift +++ b/Sources/Differentiator/SectionModel.swift @@ -42,3 +42,12 @@ extension SectionModel { self.items = items } } + +extension SectionModel + : Equatable where Section: Equatable, ItemType: Equatable { + + public static func == (lhs: SectionModel, rhs: SectionModel) -> Bool { + return lhs.model == rhs.model + && lhs.items == rhs.items + } +} diff --git a/Sources/Differentiator/Utilities.swift b/Sources/Differentiator/Utilities.swift index c884f57a..7398184f 100644 --- a/Sources/Differentiator/Utilities.swift +++ b/Sources/Differentiator/Utilities.swift @@ -13,7 +13,7 @@ enum DifferentiatorError : Error { case preconditionFailed(message: String) } -func precondition(_ condition: Bool, _ message: @autoclosure() -> String) throws -> () { +func precondition(_ condition: Bool, _ message: @autoclosure() -> String) throws { if condition { return } diff --git a/Sources/RxDataSources/AnimationConfiguration.swift b/Sources/RxDataSources/AnimationConfiguration.swift index 3d08a61f..72749e85 100644 --- a/Sources/RxDataSources/AnimationConfiguration.swift +++ b/Sources/RxDataSources/AnimationConfiguration.swift @@ -14,13 +14,13 @@ Exposes custom animation styles for insertion, deletion and reloading behavior. */ public struct AnimationConfiguration { - public let insertAnimation: UITableViewRowAnimation - public let reloadAnimation: UITableViewRowAnimation - public let deleteAnimation: UITableViewRowAnimation + public let insertAnimation: UITableView.RowAnimation + public let reloadAnimation: UITableView.RowAnimation + public let deleteAnimation: UITableView.RowAnimation - public init(insertAnimation: UITableViewRowAnimation = .automatic, - reloadAnimation: UITableViewRowAnimation = .automatic, - deleteAnimation: UITableViewRowAnimation = .automatic) { + public init(insertAnimation: UITableView.RowAnimation = .automatic, + reloadAnimation: UITableView.RowAnimation = .automatic, + deleteAnimation: UITableView.RowAnimation = .automatic) { self.insertAnimation = insertAnimation self.reloadAnimation = reloadAnimation self.deleteAnimation = deleteAnimation diff --git a/Sources/RxDataSources/CollectionViewSectionedDataSource.swift b/Sources/RxDataSources/CollectionViewSectionedDataSource.swift index 6146baec..ebb5645d 100644 --- a/Sources/RxDataSources/CollectionViewSectionedDataSource.swift +++ b/Sources/RxDataSources/CollectionViewSectionedDataSource.swift @@ -14,16 +14,16 @@ import RxCocoa #endif import Differentiator -open class CollectionViewSectionedDataSource +open class CollectionViewSectionedDataSource : NSObject , UICollectionViewDataSource , SectionedViewDataSourceType { - public typealias I = S.Item - public typealias Section = S - public typealias ConfigureCell = (CollectionViewSectionedDataSource, UICollectionView, IndexPath, I) -> UICollectionViewCell - public typealias ConfigureSupplementaryView = (CollectionViewSectionedDataSource, UICollectionView, String, IndexPath) -> UICollectionReusableView - public typealias MoveItem = (CollectionViewSectionedDataSource, _ sourceIndexPath:IndexPath, _ destinationIndexPath:IndexPath) -> Void - public typealias CanMoveItemAtIndexPath = (CollectionViewSectionedDataSource, IndexPath) -> Bool + public typealias Item = Section.Item + public typealias Section = Section + public typealias ConfigureCell = (CollectionViewSectionedDataSource
, UICollectionView, IndexPath, Item) -> UICollectionViewCell + public typealias ConfigureSupplementaryView = (CollectionViewSectionedDataSource
, UICollectionView, String, IndexPath) -> UICollectionReusableView + public typealias MoveItem = (CollectionViewSectionedDataSource
, _ sourceIndexPath:IndexPath, _ destinationIndexPath:IndexPath) -> Void + public typealias CanMoveItemAtIndexPath = (CollectionViewSectionedDataSource
, IndexPath) -> Bool public init( @@ -56,20 +56,20 @@ open class CollectionViewSectionedDataSource // and their relationship with section. // If particular item is mutable, that is irrelevant for this logic to function // properly. - public typealias SectionModelSnapshot = SectionModel + public typealias SectionModelSnapshot = SectionModel private var _sectionModels: [SectionModelSnapshot] = [] - open var sectionModels: [S] { + open var sectionModels: [Section] { return _sectionModels.map { Section(original: $0.model, items: $0.items) } } - open subscript(section: Int) -> S { + open subscript(section: Int) -> Section { let sectionModel = self._sectionModels[section] - return S(original: sectionModel.model, items: sectionModel.items) + return Section(original: sectionModel.model, items: sectionModel.items) } - open subscript(indexPath: IndexPath) -> I { + open subscript(indexPath: IndexPath) -> Item { get { return self._sectionModels[indexPath.section].items[indexPath.item] } @@ -81,10 +81,15 @@ open class CollectionViewSectionedDataSource } open func model(at indexPath: IndexPath) throws -> Any { + guard indexPath.section < self._sectionModels.count, + indexPath.item < self._sectionModels[indexPath.section].items.count else { + throw RxDataSourceError.outOfBounds(indexPath: indexPath) + } + return self[indexPath] } - open func setSections(_ sections: [S]) { + open func setSections(_ sections: [Section]) { self._sectionModels = sections.map { SectionModelSnapshot(model: $0, items: $0.items) } } @@ -111,7 +116,7 @@ open class CollectionViewSectionedDataSource #endif } } - open var canMoveItemAtIndexPath: ((CollectionViewSectionedDataSource, IndexPath) -> Bool)? { + open var canMoveItemAtIndexPath: ((CollectionViewSectionedDataSource
, IndexPath) -> Bool)? { didSet { #if DEBUG ensureNotMutatedAfterBinding() diff --git a/Sources/RxDataSources/DataSources.swift b/Sources/RxDataSources/DataSources.swift index 0f05c189..25b10c60 100644 --- a/Sources/RxDataSources/DataSources.swift +++ b/Sources/RxDataSources/DataSources.swift @@ -10,11 +10,12 @@ import Foundation @_exported import Differentiator -enum RxDataSourceError : Error { +enum RxDataSourceError: Error { case preconditionFailed(message: String) + case outOfBounds(indexPath: IndexPath) } -func rxPrecondition(_ condition: Bool, _ message: @autoclosure() -> String) throws -> () { +func rxPrecondition(_ condition: Bool, _ message: @autoclosure() -> String) throws { if condition { return } diff --git a/Sources/RxDataSources/Info.plist b/Sources/RxDataSources/Info.plist index 49ca846d..d7feac3e 100644 --- a/Sources/RxDataSources/Info.plist +++ b/Sources/RxDataSources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.0.2 + 4.0.1 CFBundleSignature ???? CFBundleVersion diff --git a/Sources/RxDataSources/RxCollectionViewSectionedAnimatedDataSource.swift b/Sources/RxDataSources/RxCollectionViewSectionedAnimatedDataSource.swift index d3fa7076..e17fcc24 100644 --- a/Sources/RxDataSources/RxCollectionViewSectionedAnimatedDataSource.swift +++ b/Sources/RxDataSources/RxCollectionViewSectionedAnimatedDataSource.swift @@ -15,15 +15,11 @@ import RxCocoa #endif import Differentiator -/* - This is commented becuse collection view has bugs when doing animated updates. - Take a look at randomized sections. -*/ -open class RxCollectionViewSectionedAnimatedDataSource - : CollectionViewSectionedDataSource +open class RxCollectionViewSectionedAnimatedDataSource + : CollectionViewSectionedDataSource
, RxCollectionViewDataSourceType { - public typealias Element = [S] - public typealias DecideViewTransition = (CollectionViewSectionedDataSource, UICollectionView, [Changeset]) -> ViewTransition + public typealias Element = [Section] + public typealias DecideViewTransition = (CollectionViewSectionedDataSource
, UICollectionView, [Changeset
]) -> ViewTransition // animation configuration public var animationConfiguration: AnimationConfiguration @@ -47,82 +43,57 @@ open class RxCollectionViewSectionedAnimatedDataSource)>() - - /** - This method exists because collection view updates are throttled because of internal collection view bugs. - Collection view behaves poorly during fast updates, so this should remedy those issues. - */ - open func collectionView(_ collectionView: UICollectionView, throttledObservedEvent event: Event) { + open func collectionView(_ collectionView: UICollectionView, observedEvent: Event) { Binder(self) { dataSource, newSections in - let oldSections = dataSource.sectionModels - do { + #if DEBUG + dataSource._dataSourceBound = true + #endif + if !dataSource.dataSet { + dataSource.dataSet = true + dataSource.setSections(newSections) + collectionView.reloadData() + } + else { // if view is not in view hierarchy, performing batch updates will crash the app if collectionView.window == nil { dataSource.setSections(newSections) collectionView.reloadData() return } - let differences = try Diff.differencesForSectionedView(initialSections: oldSections, finalSections: newSections) - - switch self.decideViewTransition(self, collectionView, differences) { - case .animated: - for difference in differences { - dataSource.setSections(difference.finalSections) - - collectionView.performBatchUpdates(difference, animationConfiguration: self.animationConfiguration) + let oldSections = dataSource.sectionModels + do { + let differences = try Diff.differencesForSectionedView(initialSections: oldSections, finalSections: newSections) + + switch dataSource.decideViewTransition(dataSource, collectionView, differences) { + case .animated: + // each difference must be run in a separate 'performBatchUpdates', otherwise it crashes. + // this is a limitation of Diff tool + for difference in differences { + let updateBlock = { + // sections must be set within updateBlock in 'performBatchUpdates' + dataSource.setSections(difference.finalSections) + collectionView.batchUpdates(difference, animationConfiguration: dataSource.animationConfiguration) + } + collectionView.performBatchUpdates(updateBlock, completion: nil) + } + + case .reload: + dataSource.setSections(newSections) + collectionView.reloadData() + return } - case .reload: - self.setSections(newSections) - collectionView.reloadData() } - } - catch let e { - #if DEBUG - print("Error while binding data animated: \(e)\nFallback to normal `reloadData` behavior.") + catch let e { rxDebugFatalError(e) - #endif - self.setSections(newSections) - collectionView.reloadData() - } - }.on(event) - } - - open func collectionView(_ collectionView: UICollectionView, observedEvent: Event) { - Binder(self) { dataSource, newSections in - #if DEBUG - self._dataSourceBound = true - #endif - if !self.dataSet { - self.dataSet = true - dataSource.setSections(newSections) - collectionView.reloadData() - } - else { - let element = (collectionView, observedEvent) - dataSource.partialUpdateEvent.on(.next(element)) + dataSource.setSections(newSections) + collectionView.reloadData() + } } }.on(observedEvent) } diff --git a/Sources/RxDataSources/RxCollectionViewSectionedReloadDataSource.swift b/Sources/RxDataSources/RxCollectionViewSectionedReloadDataSource.swift index 08b37b6b..bf7ae42a 100644 --- a/Sources/RxDataSources/RxCollectionViewSectionedReloadDataSource.swift +++ b/Sources/RxDataSources/RxCollectionViewSectionedReloadDataSource.swift @@ -15,16 +15,16 @@ import RxCocoa #endif import Differentiator -open class RxCollectionViewSectionedReloadDataSource - : CollectionViewSectionedDataSource +open class RxCollectionViewSectionedReloadDataSource + : CollectionViewSectionedDataSource
, RxCollectionViewDataSourceType { - public typealias Element = [S] + public typealias Element = [Section] open func collectionView(_ collectionView: UICollectionView, observedEvent: Event) { Binder(self) { dataSource, element in #if DEBUG - self._dataSourceBound = true + dataSource._dataSourceBound = true #endif dataSource.setSections(element) collectionView.reloadData() diff --git a/Sources/RxDataSources/RxPickerViewAdapter.swift b/Sources/RxDataSources/RxPickerViewAdapter.swift index 331be910..d1f6ed31 100644 --- a/Sources/RxDataSources/RxPickerViewAdapter.swift +++ b/Sources/RxDataSources/RxPickerViewAdapter.swift @@ -26,7 +26,7 @@ items .disposed(by: disposeBag) */ -open class RxPickerViewStringAdapter: RxPickerViewDataSource, UIPickerViewDelegate { +open class RxPickerViewStringAdapter: RxPickerViewDataSource, UIPickerViewDelegate { /** - parameter dataSource - parameter pickerView @@ -35,9 +35,9 @@ open class RxPickerViewStringAdapter: RxPickerViewDataSource, UIPickerView - parameter component */ public typealias TitleForRow = ( - _ dataSource: RxPickerViewStringAdapter, + _ dataSource: RxPickerViewStringAdapter, _ pickerView: UIPickerView, - _ components: T, + _ components: Components, _ row: Int, _ component: Int ) -> String? @@ -50,7 +50,7 @@ open class RxPickerViewStringAdapter: RxPickerViewDataSource, UIPickerView - parameter numberOfRowsInComponent: Implementation of corresponding delegate method. - parameter titleForRow: Implementation of corresponding adapter method that converts component to `String`. */ - public init(components: T, + public init(components: Components, numberOfComponents: @escaping NumberOfComponents, numberOfRowsInComponent: @escaping NumberOfRowsInComponent, titleForRow: @escaping TitleForRow) { @@ -76,7 +76,7 @@ open class RxPickerViewStringAdapter: RxPickerViewDataSource, UIPickerView .disposed(by: disposeBag) */ -open class RxPickerViewAttributedStringAdapter: RxPickerViewDataSource, UIPickerViewDelegate { +open class RxPickerViewAttributedStringAdapter: RxPickerViewDataSource, UIPickerViewDelegate { /** - parameter dataSource - parameter pickerView @@ -85,9 +85,9 @@ open class RxPickerViewAttributedStringAdapter: RxPickerViewDataSource, UI - parameter component */ public typealias AttributedTitleForRow = ( - _ dataSource: RxPickerViewAttributedStringAdapter, + _ dataSource: RxPickerViewAttributedStringAdapter, _ pickerView: UIPickerView, - _ components: T, + _ components: Components, _ row: Int, _ component: Int ) -> NSAttributedString? @@ -100,7 +100,7 @@ open class RxPickerViewAttributedStringAdapter: RxPickerViewDataSource, UI - parameter numberOfRowsInComponent: Implementation of corresponding delegate method. - parameter attributedTitleForRow: Implementation of corresponding adapter method that converts component to `NSAttributedString`. */ - public init(components: T, + public init(components: Components, numberOfComponents: @escaping NumberOfComponents, numberOfRowsInComponent: @escaping NumberOfRowsInComponent, attributedTitleForRow: @escaping AttributedTitleForRow) { @@ -126,7 +126,7 @@ open class RxPickerViewAttributedStringAdapter: RxPickerViewDataSource, UI .disposed(by: disposeBag) */ -open class RxPickerViewViewAdapter: RxPickerViewDataSource, UIPickerViewDelegate { +open class RxPickerViewViewAdapter: RxPickerViewDataSource, UIPickerViewDelegate { /** - parameter dataSource - parameter pickerView @@ -136,9 +136,9 @@ open class RxPickerViewViewAdapter: RxPickerViewDataSource, UIPickerViewDe - parameter view */ public typealias ViewForRow = ( - _ dataSource: RxPickerViewViewAdapter, + _ dataSource: RxPickerViewViewAdapter, _ pickerView: UIPickerView, - _ components: T, + _ components: Components, _ row: Int, _ component: Int, _ view: UIView? @@ -152,7 +152,7 @@ open class RxPickerViewViewAdapter: RxPickerViewDataSource, UIPickerViewDe - parameter numberOfRowsInComponent: Implementation of corresponding delegate method. - parameter attributedTitleForRow: Implementation of corresponding adapter method that converts component to `UIView`. */ - public init(components: T, + public init(components: Components, numberOfComponents: @escaping NumberOfComponents, numberOfRowsInComponent: @escaping NumberOfRowsInComponent, viewForRow: @escaping ViewForRow) { @@ -168,7 +168,7 @@ open class RxPickerViewViewAdapter: RxPickerViewDataSource, UIPickerViewDe } /// A reactive UIPickerView data source -open class RxPickerViewDataSource: NSObject, UIPickerViewDataSource { +open class RxPickerViewDataSource: NSObject, UIPickerViewDataSource { /** - parameter dataSource - parameter pickerView @@ -177,7 +177,7 @@ open class RxPickerViewDataSource: NSObject, UIPickerViewDataSource { public typealias NumberOfComponents = ( _ dataSource: RxPickerViewDataSource, _ pickerView: UIPickerView, - _ components: T) -> Int + _ components: Components) -> Int /** - parameter dataSource - parameter pickerView @@ -187,18 +187,18 @@ open class RxPickerViewDataSource: NSObject, UIPickerViewDataSource { public typealias NumberOfRowsInComponent = ( _ dataSource: RxPickerViewDataSource, _ pickerView: UIPickerView, - _ components: T, + _ components: Components, _ component: Int ) -> Int - fileprivate var components: T + fileprivate var components: Components /** - parameter components: Initial content value. - parameter numberOfComponents: Implementation of corresponding delegate method. - parameter numberOfRowsInComponent: Implementation of corresponding delegate method. */ - init(components: T, + init(components: Components, numberOfComponents: @escaping NumberOfComponents, numberOfRowsInComponent: @escaping NumberOfRowsInComponent) { self.components = components @@ -210,7 +210,7 @@ open class RxPickerViewDataSource: NSObject, UIPickerViewDataSource { private let numberOfComponents: NumberOfComponents private let numberOfRowsInComponent: NumberOfRowsInComponent - //MARK: UIPickerViewDataSource + // MARK: UIPickerViewDataSource public func numberOfComponents(in pickerView: UIPickerView) -> Int { return numberOfComponents(self, pickerView, components) @@ -222,8 +222,8 @@ open class RxPickerViewDataSource: NSObject, UIPickerViewDataSource { } extension RxPickerViewDataSource: RxPickerViewDataSourceType { - public func pickerView(_ pickerView: UIPickerView, observedEvent: Event) { - Binder(self) { (dataSource, components) in + public func pickerView(_ pickerView: UIPickerView, observedEvent: Event) { + Binder(self) { dataSource, components in dataSource.components = components pickerView.reloadAllComponents() }.on(observedEvent) diff --git a/Sources/RxDataSources/RxTableViewSectionedAnimatedDataSource.swift b/Sources/RxDataSources/RxTableViewSectionedAnimatedDataSource.swift index a7890e47..b7f07f86 100644 --- a/Sources/RxDataSources/RxTableViewSectionedAnimatedDataSource.swift +++ b/Sources/RxDataSources/RxTableViewSectionedAnimatedDataSource.swift @@ -15,11 +15,11 @@ import RxCocoa #endif import Differentiator -open class RxTableViewSectionedAnimatedDataSource - : TableViewSectionedDataSource +open class RxTableViewSectionedAnimatedDataSource + : TableViewSectionedDataSource
, RxTableViewDataSourceType { - public typealias Element = [S] - public typealias DecideViewTransition = (TableViewSectionedDataSource, UITableView, [Changeset]) -> ViewTransition + public typealias Element = [Section] + public typealias DecideViewTransition = (TableViewSectionedDataSource
, UITableView, [Changeset
]) -> ViewTransition /// Animation configuration for data source public var animationConfiguration: AnimationConfiguration @@ -78,44 +78,54 @@ open class RxTableViewSectionedAnimatedDataSource open func tableView(_ tableView: UITableView, observedEvent: Event) { Binder(self) { dataSource, newSections in #if DEBUG - self._dataSourceBound = true + dataSource._dataSourceBound = true #endif - if !self.dataSet { - self.dataSet = true + if !dataSource.dataSet { + dataSource.dataSet = true dataSource.setSections(newSections) tableView.reloadData() } else { - DispatchQueue.main.async { - // if view is not in view hierarchy, performing batch updates will crash the app - if tableView.window == nil { - dataSource.setSections(newSections) - tableView.reloadData() - return - } - let oldSections = dataSource.sectionModels - do { - let differences = try Diff.differencesForSectionedView(initialSections: oldSections, finalSections: newSections) - - switch self.decideViewTransition(self, tableView, differences) { - case .animated: - for difference in differences { + // if view is not in view hierarchy, performing batch updates will crash the app + if tableView.window == nil { + dataSource.setSections(newSections) + tableView.reloadData() + return + } + let oldSections = dataSource.sectionModels + do { + let differences = try Diff.differencesForSectionedView(initialSections: oldSections, finalSections: newSections) + + switch dataSource.decideViewTransition(dataSource, tableView, differences) { + case .animated: + // each difference must be run in a separate 'performBatchUpdates', otherwise it crashes. + // this is a limitation of Diff tool + for difference in differences { + let updateBlock = { + // sections must be set within updateBlock in 'performBatchUpdates' dataSource.setSections(difference.finalSections) - - tableView.performBatchUpdates(difference, animationConfiguration: self.animationConfiguration) + tableView.batchUpdates(difference, animationConfiguration: dataSource.animationConfiguration) + } + if #available(iOS 11, tvOS 11, *) { + tableView.performBatchUpdates(updateBlock, completion: nil) + } else { + tableView.beginUpdates() + updateBlock() + tableView.endUpdates() } - case .reload: - self.setSections(newSections) - tableView.reloadData() - return } - } - catch let e { - rxDebugFatalError(e) - self.setSections(newSections) + + case .reload: + dataSource.setSections(newSections) tableView.reloadData() + return } } + catch let e { + rxDebugFatalError(e) + dataSource.setSections(newSections) + tableView.reloadData() + } } }.on(observedEvent) } diff --git a/Sources/RxDataSources/RxTableViewSectionedReloadDataSource.swift b/Sources/RxDataSources/RxTableViewSectionedReloadDataSource.swift index 26629ce7..19a924a4 100644 --- a/Sources/RxDataSources/RxTableViewSectionedReloadDataSource.swift +++ b/Sources/RxDataSources/RxTableViewSectionedReloadDataSource.swift @@ -15,15 +15,15 @@ import RxCocoa #endif import Differentiator -open class RxTableViewSectionedReloadDataSource - : TableViewSectionedDataSource +open class RxTableViewSectionedReloadDataSource + : TableViewSectionedDataSource
, RxTableViewDataSourceType { - public typealias Element = [S] + public typealias Element = [Section] open func tableView(_ tableView: UITableView, observedEvent: Event) { Binder(self) { dataSource, element in #if DEBUG - self._dataSourceBound = true + dataSource._dataSourceBound = true #endif dataSource.setSections(element) tableView.reloadData() diff --git a/Sources/RxDataSources/TableViewSectionedDataSource.swift b/Sources/RxDataSources/TableViewSectionedDataSource.swift index e2b48a60..0ba1558a 100644 --- a/Sources/RxDataSources/TableViewSectionedDataSource.swift +++ b/Sources/RxDataSources/TableViewSectionedDataSource.swift @@ -14,23 +14,22 @@ import RxCocoa #endif import Differentiator -open class TableViewSectionedDataSource +open class TableViewSectionedDataSource : NSObject , UITableViewDataSource , SectionedViewDataSourceType { - public typealias I = S.Item - public typealias Section = S + public typealias Item = Section.Item - public typealias ConfigureCell = (TableViewSectionedDataSource, UITableView, IndexPath, I) -> UITableViewCell - public typealias TitleForHeaderInSection = (TableViewSectionedDataSource, Int) -> String? - public typealias TitleForFooterInSection = (TableViewSectionedDataSource, Int) -> String? - public typealias CanEditRowAtIndexPath = (TableViewSectionedDataSource, IndexPath) -> Bool - public typealias CanMoveRowAtIndexPath = (TableViewSectionedDataSource, IndexPath) -> Bool + public typealias ConfigureCell = (TableViewSectionedDataSource
, UITableView, IndexPath, Item) -> UITableViewCell + public typealias TitleForHeaderInSection = (TableViewSectionedDataSource
, Int) -> String? + public typealias TitleForFooterInSection = (TableViewSectionedDataSource
, Int) -> String? + public typealias CanEditRowAtIndexPath = (TableViewSectionedDataSource
, IndexPath) -> Bool + public typealias CanMoveRowAtIndexPath = (TableViewSectionedDataSource
, IndexPath) -> Bool #if os(iOS) - public typealias SectionIndexTitles = (TableViewSectionedDataSource) -> [String]? - public typealias SectionForSectionIndexTitle = (TableViewSectionedDataSource, _ title: String, _ index: Int) -> Int + public typealias SectionIndexTitles = (TableViewSectionedDataSource
) -> [String]? + public typealias SectionForSectionIndexTitle = (TableViewSectionedDataSource
, _ title: String, _ index: Int) -> Int #endif #if os(iOS) @@ -38,8 +37,8 @@ open class TableViewSectionedDataSource configureCell: @escaping ConfigureCell, titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil }, titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil }, - canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in false }, - canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in false }, + canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in true }, + canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in true }, sectionIndexTitles: @escaping SectionIndexTitles = { _ in nil }, sectionForSectionIndexTitle: @escaping SectionForSectionIndexTitle = { _, _, index in index } ) { @@ -56,8 +55,8 @@ open class TableViewSectionedDataSource configureCell: @escaping ConfigureCell, titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil }, titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil }, - canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in false }, - canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in false } + canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in true }, + canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in true } ) { self.configureCell = configureCell self.titleForHeaderInSection = titleForHeaderInSection @@ -85,20 +84,20 @@ open class TableViewSectionedDataSource // and their relationship with section. // If particular item is mutable, that is irrelevant for this logic to function // properly. - public typealias SectionModelSnapshot = SectionModel + public typealias SectionModelSnapshot = SectionModel private var _sectionModels: [SectionModelSnapshot] = [] - open var sectionModels: [S] { + open var sectionModels: [Section] { return _sectionModels.map { Section(original: $0.model, items: $0.items) } } - open subscript(section: Int) -> S { + open subscript(section: Int) -> Section { let sectionModel = self._sectionModels[section] - return S(original: sectionModel.model, items: sectionModel.items) + return Section(original: sectionModel.model, items: sectionModel.items) } - open subscript(indexPath: IndexPath) -> I { + open subscript(indexPath: IndexPath) -> Item { get { return self._sectionModels[indexPath.section].items[indexPath.item] } @@ -110,10 +109,15 @@ open class TableViewSectionedDataSource } open func model(at indexPath: IndexPath) throws -> Any { + guard indexPath.section < self._sectionModels.count, + indexPath.item < self._sectionModels[indexPath.section].items.count else { + throw RxDataSourceError.outOfBounds(indexPath: indexPath) + } + return self[indexPath] } - open func setSections(_ sections: [S]) { + open func setSections(_ sections: [Section]) { self._sectionModels = sections.map { SectionModelSnapshot(model: $0, items: $0.items) } } @@ -155,8 +159,6 @@ open class TableViewSectionedDataSource } } - open var rowAnimation: UITableViewRowAnimation = .automatic - #if os(iOS) open var sectionIndexTitles: SectionIndexTitles { didSet { diff --git a/Sources/RxDataSources/UI+SectionedViewType.swift b/Sources/RxDataSources/UI+SectionedViewType.swift index d1f89a37..033fc1d1 100644 --- a/Sources/RxDataSources/UI+SectionedViewType.swift +++ b/Sources/RxDataSources/UI+SectionedViewType.swift @@ -11,10 +11,6 @@ import Foundation import UIKit import Differentiator -#if swift(>=4.2) -public typealias UITableViewRowAnimation = UITableView.RowAnimation -#endif - func indexSet(_ values: [Int]) -> IndexSet { let indexSet = NSMutableIndexSet() for i in values { @@ -25,11 +21,11 @@ func indexSet(_ values: [Int]) -> IndexSet { extension UITableView : SectionedViewType { - public func insertItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) { + public func insertItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) { self.insertRows(at: paths, with: animationStyle) } - public func deleteItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) { + public func deleteItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) { self.deleteRows(at: paths, with: animationStyle) } @@ -37,15 +33,15 @@ extension UITableView : SectionedViewType { self.moveRow(at: from, to: to) } - public func reloadItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) { + public func reloadItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) { self.reloadRows(at: paths, with: animationStyle) } - public func insertSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) { + public func insertSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) { self.insertSections(indexSet(sections), with: animationStyle) } - public func deleteSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) { + public func deleteSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) { self.deleteSections(indexSet(sections), with: animationStyle) } @@ -53,23 +49,17 @@ extension UITableView : SectionedViewType { self.moveSection(from, toSection: to) } - public func reloadSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) { + public func reloadSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) { self.reloadSections(indexSet(sections), with: animationStyle) } - - public func performBatchUpdates(_ changes: Changeset, animationConfiguration: AnimationConfiguration) { - self.beginUpdates() - _performBatchUpdates(self, changes: changes, animationConfiguration: animationConfiguration) - self.endUpdates() - } } extension UICollectionView : SectionedViewType { - public func insertItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) { + public func insertItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) { self.insertItems(at: paths) } - public func deleteItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) { + public func deleteItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) { self.deleteItems(at: paths) } @@ -77,15 +67,15 @@ extension UICollectionView : SectionedViewType { self.moveItem(at: from, to: to) } - public func reloadItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) { + public func reloadItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) { self.reloadItems(at: paths) } - public func insertSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) { + public func insertSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) { self.insertSections(indexSet(sections)) } - public func deleteSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) { + public func deleteSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) { self.deleteSections(indexSet(sections)) } @@ -93,62 +83,54 @@ extension UICollectionView : SectionedViewType { self.moveSection(from, toSection: to) } - public func reloadSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) { + public func reloadSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) { self.reloadSections(indexSet(sections)) } - - public func performBatchUpdates(_ changes: Changeset, animationConfiguration: AnimationConfiguration) { - self.performBatchUpdates({ () -> Void in - _performBatchUpdates(self, changes: changes, animationConfiguration: animationConfiguration) - }, completion: { (completed: Bool) -> Void in - }) - } } public protocol SectionedViewType { - func insertItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) - func deleteItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) + func insertItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) + func deleteItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) func moveItemAtIndexPath(_ from: IndexPath, to: IndexPath) - func reloadItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation) + func reloadItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableView.RowAnimation) - func insertSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) - func deleteSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) + func insertSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) + func deleteSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) func moveSection(_ from: Int, to: Int) - func reloadSections(_ sections: [Int], animationStyle: UITableViewRowAnimation) - - func performBatchUpdates(_ changes: Changeset, animationConfiguration: AnimationConfiguration) + func reloadSections(_ sections: [Int], animationStyle: UITableView.RowAnimation) } -func _performBatchUpdates(_ view: V, changes: Changeset, animationConfiguration:AnimationConfiguration) { - typealias I = S.Item - - view.deleteSections(changes.deletedSections, animationStyle: animationConfiguration.deleteAnimation) - // Updated sections doesn't mean reload entire section, somebody needs to update the section view manually - // otherwise all cells will be reloaded for nothing. - //view.reloadSections(changes.updatedSections, animationStyle: rowAnimation) - view.insertSections(changes.insertedSections, animationStyle: animationConfiguration.insertAnimation) - for (from, to) in changes.movedSections { - view.moveSection(from, to: to) - } - - view.deleteItemsAtIndexPaths( - changes.deletedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) }, - animationStyle: animationConfiguration.deleteAnimation - ) - view.insertItemsAtIndexPaths( - changes.insertedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) }, - animationStyle: animationConfiguration.insertAnimation - ) - view.reloadItemsAtIndexPaths( - changes.updatedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) }, - animationStyle: animationConfiguration.reloadAnimation - ) - - for (from, to) in changes.movedItems { - view.moveItemAtIndexPath( - IndexPath(item: from.itemIndex, section: from.sectionIndex), - to: IndexPath(item: to.itemIndex, section: to.sectionIndex) +extension SectionedViewType { + public func batchUpdates
(_ changes: Changeset
, animationConfiguration: AnimationConfiguration) { + // swiftlint:disable:next nesting + typealias Item = Section.Item + + deleteSections(changes.deletedSections, animationStyle: animationConfiguration.deleteAnimation) + + insertSections(changes.insertedSections, animationStyle: animationConfiguration.insertAnimation) + for (from, to) in changes.movedSections { + moveSection(from, to: to) + } + + deleteItemsAtIndexPaths( + changes.deletedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) }, + animationStyle: animationConfiguration.deleteAnimation + ) + insertItemsAtIndexPaths( + changes.insertedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) }, + animationStyle: animationConfiguration.insertAnimation + ) + reloadItemsAtIndexPaths( + changes.updatedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) }, + animationStyle: animationConfiguration.reloadAnimation ) + + for (from, to) in changes.movedItems { + moveItemAtIndexPath( + IndexPath(item: from.itemIndex, section: from.sectionIndex), + to: IndexPath(item: to.itemIndex, section: to.sectionIndex) + ) + } } } #endif diff --git a/Tests/RxDataSourcesTests/AlgorithmTests.swift b/Tests/RxDataSourcesTests/AlgorithmTests.swift index 3fd09223..e90a464c 100644 --- a/Tests/RxDataSourcesTests/AlgorithmTests.swift +++ b/Tests/RxDataSourcesTests/AlgorithmTests.swift @@ -22,7 +22,7 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]) ] @@ -31,7 +31,7 @@ extension AlgorithmTests { i(0, ""), i(1, ""), i(2, ""), - i(3, ""), + i(3, "") ]) ] @@ -48,14 +48,14 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]) ] let final: [s] = [ s(1, [ i(0, ""), - i(2, ""), + i(2, "") ]) ] @@ -72,7 +72,7 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]) ] @@ -80,7 +80,7 @@ extension AlgorithmTests { s(1, [ i(1, ""), i(2, ""), - i(0, ""), + i(0, "") ]) ] @@ -97,7 +97,7 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]) ] @@ -105,7 +105,7 @@ extension AlgorithmTests { s(1, [ i(2, ""), i(0, ""), - i(1, ""), + i(1, "") ]) ] @@ -122,7 +122,7 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]) ] @@ -130,7 +130,7 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, "u"), - i(2, ""), + i(2, "") ]) ] @@ -147,7 +147,7 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]) ] @@ -155,7 +155,7 @@ extension AlgorithmTests { s(1, [ i(1, "u"), i(0, ""), - i(2, ""), + i(2, "") ]) ] @@ -181,7 +181,7 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]) ] @@ -189,13 +189,13 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]), s(2, [ i(3, ""), i(4, ""), - i(5, ""), - ]), + i(5, "") + ]) ] let differences = try! Diff.differencesForSectionedView(initialSections: initial, finalSections: final) @@ -211,7 +211,7 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]) ] @@ -232,36 +232,36 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]), s(2, [ i(3, ""), i(4, ""), - i(5, ""), + i(5, "") ]), s(3, [ i(6, ""), i(7, ""), - i(8, ""), - ]), + i(8, "") + ]) ] let final: [s] = [ s(2, [ i(3, ""), i(4, ""), - i(5, ""), + i(5, "") ]), s(3, [ i(6, ""), i(7, ""), - i(8, ""), + i(8, "") ]), s(1, [ i(0, ""), i(1, ""), - i(2, ""), - ]), + i(2, "") + ]) ] let differences = try! Diff.differencesForSectionedView(initialSections: initial, finalSections: final) @@ -277,36 +277,36 @@ extension AlgorithmTests { s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]), s(2, [ i(3, ""), i(4, ""), - i(5, ""), + i(5, "") ]), s(3, [ i(6, ""), i(7, ""), - i(8, ""), - ]), + i(8, "") + ]) ] let final: [s] = [ s(3, [ i(6, ""), i(7, ""), - i(8, ""), + i(8, "") ]), s(1, [ i(0, ""), i(1, ""), - i(2, ""), + i(2, "") ]), s(2, [ i(3, ""), i(4, ""), - i(5, ""), - ]), + i(5, "") + ]) ] let differences = try! Diff.differencesForSectionedView(initialSections: initial, finalSections: final) @@ -323,21 +323,21 @@ extension AlgorithmTests { func testThrowsErrorOnDuplicateItem() { let initial: [s] = [ s(1, [ - i(1111, ""), + i(1111, "") ]), s(2, [ - i(1111, ""), - ]), + i(1111, "") + ]) ] do { _ = try Diff.differencesForSectionedView(initialSections: initial, finalSections: initial) - XCTFail() + XCTFail("Should throw exception") } catch let exception { guard case let .duplicateItem(item) = exception as! Diff.Error else { - XCTFail() + XCTFail("Not required error") return } @@ -348,26 +348,26 @@ extension AlgorithmTests { func testThrowsErrorOnDuplicateSection() { let initial: [s] = [ s(1, [ - i(1111, ""), + i(1111, "") ]), s(1, [ - i(1112, ""), - ]), + i(1112, "") + ]) ] do { _ = try Diff.differencesForSectionedView(initialSections: initial, finalSections: initial) - XCTFail() + XCTFail("Should throw exception") } catch let exception { guard case let .duplicateSection(section) = exception as! Diff.Error else { - XCTFail() + XCTFail("Not required error") return } XCTAssertEqual(section as! s, s(1, [ - i(1112, ""), + i(1112, "") ])) } } @@ -375,23 +375,23 @@ extension AlgorithmTests { func testThrowsErrorOnInvalidInitializerImplementation1() { let initial: [sInvalidInitializerImplementation1] = [ sInvalidInitializerImplementation1(1, [ - i(1111, ""), - ]), + i(1111, "") + ]) ] do { _ = try Diff.differencesForSectionedView(initialSections: initial, finalSections: initial) - XCTFail() + XCTFail("Should throw exception") } catch let exception { guard case let .invalidInitializerImplementation(section, expectedItems, identifier) = exception as! Diff.Error else { - XCTFail() + XCTFail("Not required error") return } XCTAssertEqual(section as! sInvalidInitializerImplementation1, sInvalidInitializerImplementation1(1, [ i(1111, ""), - i(1111, ""), + i(1111, "") ])) XCTAssertEqual(expectedItems as! [i], [i(1111, "")]) @@ -402,22 +402,22 @@ extension AlgorithmTests { func testThrowsErrorOnInvalidInitializerImplementation2() { let initial: [sInvalidInitializerImplementation2] = [ sInvalidInitializerImplementation2(1, [ - i(1111, ""), - ]), + i(1111, "") + ]) ] do { _ = try Diff.differencesForSectionedView(initialSections: initial, finalSections: initial) - XCTFail() + XCTFail("Should throw exception") } catch let exception { guard case let .invalidInitializerImplementation(section, expectedItems, identifier) = exception as! Diff.Error else { - XCTFail() + XCTFail("Not required error") return } XCTAssertEqual(section as! sInvalidInitializerImplementation2, sInvalidInitializerImplementation2(-1, [ - i(1111, ""), + i(1111, "") ])) XCTAssertEqual(expectedItems as! [i], [i(1111, "")]) @@ -431,20 +431,20 @@ extension AlgorithmTests { func testCase1() { let initial: [s] = [ s(1, [ - i(1111, ""), + i(1111, "") ]), s(2, [ - i(2222, ""), - ]), + i(2222, "") + ]) ] let final: [s] = [ s(2, [ - i(0, "1"), + i(0, "1") ]), s(1, [ - ]), + ]) ] let differences = try! Diff.differencesForSectionedView(initialSections: initial, finalSections: final) @@ -457,13 +457,13 @@ extension AlgorithmTests { s(4, [ i(10, ""), i(11, ""), - i(12, ""), + i(12, "") ]), s(9, [ i(25, ""), i(26, ""), - i(27, ""), - ]), + i(27, "") + ]) ] @@ -471,12 +471,12 @@ extension AlgorithmTests { s(9, [ i(11, "u"), i(26, ""), - i(27, "u"), + i(27, "u") ]), s(4, [ i(10, "u"), - i(12, ""), - ]), + i(12, "") + ]) ] @@ -488,25 +488,25 @@ extension AlgorithmTests { func testCase3() { let initial: [s] = [ s(4, [ - i(5, ""), + i(5, "") ]), s(6, [ i(20, ""), - i(14, ""), + i(14, "") ]), s(9, [ ]), s(2, [ i(2, ""), - i(26, ""), + i(26, "") ]), s(8, [ - i(23, ""), + i(23, "") ]), s(10, [ i(8, ""), i(18, ""), - i(13, ""), + i(13, "") ]), s(1, [ i(28, ""), @@ -517,37 +517,37 @@ extension AlgorithmTests { i(29, ""), i(24, ""), i(7, ""), - i(19, ""), - ]), + i(19, "") + ]) ] let final: [s] = [ s(4, [ - i(5, ""), + i(5, "") ]), s(6, [ i(20, "u"), - i(14, ""), + i(14, "") ]), s(9, [ - i(16, "u"), + i(16, "u") ]), s(7, [ i(17, ""), i(15, ""), - i(4, "u"), + i(4, "u") ]), s(2, [ i(2, ""), i(26, "u"), - i(23, "u"), + i(23, "u") ]), s(8, [ ]), s(10, [ i(8, "u"), i(18, "u"), - i(13, "u"), + i(13, "u") ]), s(1, [ i(28, "u"), @@ -558,8 +558,8 @@ extension AlgorithmTests { i(29, "u"), i(24, "u"), i(7, "u"), - i(19, "u"), - ]), + i(19, "u") + ]) ] diff --git a/Tests/RxDataSourcesTests/ChangeSet+TestExtensions.swift b/Tests/RxDataSourcesTests/ChangeSet+TestExtensions.swift index 1cc3865f..9a0695aa 100644 --- a/Tests/RxDataSourcesTests/ChangeSet+TestExtensions.swift +++ b/Tests/RxDataSourcesTests/ChangeSet+TestExtensions.swift @@ -15,7 +15,7 @@ fileprivate class ItemModelTypeWrapper { var deleted: Bool = false var updated: Bool = false - var moved: IndexPath? = nil + var moved: IndexPath? init(item: I) { self.item = item @@ -25,7 +25,7 @@ fileprivate class ItemModelTypeWrapper { fileprivate class SectionModelTypeWrapper { var updated: Bool = false var deleted: Bool = false - var moved: Int? = nil + var moved: Int? var items: [ItemModelTypeWrapper] @@ -86,7 +86,7 @@ extension Changeset { extension Changeset { - fileprivate func apply(original: [S]) -> [S] { + fileprivate func apply(original: [Section]) -> [Section] { let afterDeletesAndUpdates = applyDeletesAndUpdates(original: original) let afterSectionMovesAndInserts = applySectionMovesAndInserts(original: afterDeletesAndUpdates) @@ -95,8 +95,8 @@ extension Changeset { return afterItemInsertsAndMoves } - private func applyDeletesAndUpdates(original: [S]) -> [S] { - var resultAfterDeletesAndUpdates: [SectionModelTypeWrapper] = SectionModelTypeWrapper.wrap(original) + private func applyDeletesAndUpdates(original: [Section]) -> [Section] { + var resultAfterDeletesAndUpdates: [SectionModelTypeWrapper
] = SectionModelTypeWrapper.wrap(original) for index in updatedItems { resultAfterDeletesAndUpdates[index.sectionIndex].items[index.itemIndex].updated = true @@ -114,17 +114,15 @@ extension Changeset { for (sectionIndex, section) in resultAfterDeletesAndUpdates.enumerated() { section.items = section.items.filter { !$0.deleted } - for (itemIndex, item) in section.items.enumerated() { - if item.updated { - section.items[itemIndex] = ItemModelTypeWrapper(item: finalSections[sectionIndex].items[itemIndex]) - } + for (itemIndex, item) in section.items.enumerated() where item.updated { + section.items[itemIndex] = ItemModelTypeWrapper(item: finalSections[sectionIndex].items[itemIndex]) } } return SectionModelTypeWrapper.unwrap(resultAfterDeletesAndUpdates) } - private func applySectionMovesAndInserts(original: [S]) -> [S] { + private func applySectionMovesAndInserts(original: [Section]) -> [Section] { if !updatedSections.isEmpty { fatalError("Section updates aren't supported") } @@ -149,7 +147,7 @@ extension Changeset { let totalCount = original.count + insertedSections.count - var results: [S] = [] + var results: [Section] = [] for index in 0 ..< totalCount { if insertedSectionsIndexes.contains(index) { @@ -170,8 +168,8 @@ extension Changeset { return results } - private func applyItemInsertsAndMoves(original: [S]) -> [S] { - var resultAfterInsertsAndMoves: [S] = original + private func applyItemInsertsAndMoves(original: [Section]) -> [Section] { + var resultAfterInsertsAndMoves: [Section] = original let sourceIndexesThatShouldBeMoved = Set(movedItems.map { $0.from }) let destinationToSourceMapping = Dictionary(elements: self.movedItems, keySelector: { $0.to }, valueSelector: { $0.from }) @@ -210,7 +208,7 @@ extension Changeset { + movedInSection[sectionIndex] - movedOutSection[sectionIndex] - var resultItems: [S.Item] = [] + var resultItems: [Section.Item] = [] for index in 0 ..< totalCount { let itemPath = ItemPath(sectionIndex: sectionIndex, itemIndex: index) @@ -229,7 +227,7 @@ extension Changeset { } } - resultAfterInsertsAndMoves[sectionIndex] = S(original: section, items: resultItems) + resultAfterInsertsAndMoves[sectionIndex] = Section(original: section, items: resultItems) } return resultAfterInsertsAndMoves diff --git a/Tests/RxDataSourcesTests/Randomizer.swift b/Tests/RxDataSourcesTests/Randomizer.swift index 7012fdd0..1bb79944 100644 --- a/Tests/RxDataSourcesTests/Randomizer.swift +++ b/Tests/RxDataSourcesTests/Randomizer.swift @@ -21,8 +21,8 @@ struct PseudoRandomGenerator { } func get_random() -> (PseudoRandomGenerator, Int) { - let m_z = 36969 &* (self.m_z & 65535) &+ (self.m_z >> 16); - let m_w = 18000 &* (self.m_w & 65535) &+ (self.m_w >> 16); + let m_z = 36969 &* (self.m_z & 65535) &+ (self.m_z >> 16) + let m_w = 18000 &* (self.m_w & 65535) &+ (self.m_w >> 16) let val = ((m_z << 16) &+ m_w) return (PseudoRandomGenerator(m_w, m_z), Int(val % (1 << 30))) /* 32-bit result */ } diff --git a/Tests/RxDataSourcesTests/RxCollectionViewSectionedDataSource+Test.swift b/Tests/RxDataSourcesTests/RxCollectionViewSectionedDataSource+Test.swift index ceae1b91..48cb646a 100644 --- a/Tests/RxDataSourcesTests/RxCollectionViewSectionedDataSource+Test.swift +++ b/Tests/RxDataSourcesTests/RxCollectionViewSectionedDataSource+Test.swift @@ -30,7 +30,7 @@ extension RxCollectionViewSectionedDataSourceTest { let returnValue = dataSource.collectionView( collectionView, - viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, + viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: 0, section: 0) ) XCTAssertEqual(returnValue, sentinel) @@ -49,7 +49,7 @@ extension RxCollectionViewSectionedDataSourceTest { let returnValue = dataSource.collectionView( collectionView, - viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, + viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: 0, section: 0) ) XCTAssertEqual(returnValue, sentinel) @@ -70,7 +70,7 @@ extension RxCollectionViewSectionedDataSourceTest { let returnValue = dataSource.collectionView( collectionView, - viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, + viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: 0, section: 0) ) XCTAssertEqual(returnValue, sentinel) @@ -88,7 +88,7 @@ extension RxCollectionViewSectionedDataSourceTest { let returnValue = dataSource.collectionView( collectionView, - viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, + viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: 0, section: 0) ) XCTAssertEqual(returnValue, sentinel) @@ -106,7 +106,7 @@ extension RxCollectionViewSectionedDataSourceTest { let returnValue = dataSource.collectionView( collectionView, - viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, + viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: 0, section: 0) ) XCTAssertEqual(returnValue, sentinel)