diff --git a/.travis.yml b/.travis.yml index f5347f0..b3bed0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: objective-c -osx_image: xcode7.3 +osx_image: xcode8.3 rvm: - - "2.3.1" + - "2.4.1" env: global: @@ -12,9 +12,6 @@ env: - OS=macos - OS=tvos -before_install: - - brew install swiftlint - install: - gem install bundler --no-doc --no-ri - bundle install --path="./.vendor/bundle" diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a4a3b..7834114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log ## [Unreleased](https://github.com/RxSwiftCommunity/RxViewModel/tree/HEAD) +- Support for Swift 3 & 4 [\#45](https://github.com/RxSwiftCommunity/RxViewModel/pull/45) ([freak4pc](https://github.com/freak4pc)) [Full Changelog](https://github.com/RxSwiftCommunity/RxViewModel/compare/3.1.3...HEAD) diff --git a/Cartfile b/Cartfile index a855b4c..313c24d 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveX/RxSwift" ~> 2.5 +github "ReactiveX/RxSwift" ~> 3.4 diff --git a/Cartfile.resolved b/Cartfile.resolved index 1672274..c3b4814 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "ReactiveX/RxSwift" "2.6.0" +github "ReactiveX/RxSwift" "3.5.0" diff --git a/Carthage/Checkouts/RxSwift b/Carthage/Checkouts/RxSwift index 56e09ab..520b1db 160000 --- a/Carthage/Checkouts/RxSwift +++ b/Carthage/Checkouts/RxSwift @@ -1 +1 @@ -Subproject commit 56e09abb11762db6071c88bf9bf657eb8d96a96a +Subproject commit 520b1db2237f55763c7b6211dc9d8255967eee69 diff --git a/Demo/.swift-version b/Demo/.swift-version new file mode 100644 index 0000000..9f55b2c --- /dev/null +++ b/Demo/.swift-version @@ -0,0 +1 @@ +3.0 diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index 7f39438..6b79714 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -309,7 +309,7 @@ }; 607FACE41AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; - TestTargetID = 607FACCF1AFB9204008FA782; + TestTargetID = 1168B9761D2DFF2A00784841; }; }; }; @@ -411,7 +411,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 3B32E276864ED8DE0A42EB66 /* [CP] Copy Pods Resources */ = { @@ -456,7 +456,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 74F4425F80A70ACF54C96776 /* [CP] Check Pods Manifest.lock */ = { @@ -471,7 +471,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 8B85B57729C5E3D4D213BC72 /* [CP] Copy Pods Resources */ = { @@ -531,7 +531,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; F088206876394936F4C2A77D /* [CP] Copy Pods Resources */ = { @@ -627,6 +627,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; PRODUCT_BUNDLE_IDENTIFIER = es.estebantorr.Demo; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -641,6 +642,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; PRODUCT_BUNDLE_IDENTIFIER = es.estebantorr.Demo; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -655,6 +657,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "es.estebantorr.RxViewModelTests-tvOS"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.2; }; name = Debug; @@ -669,6 +672,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "es.estebantorr.RxViewModelTests-tvOS"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.2; }; name = Release; @@ -687,6 +691,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "es.estebantorr.RxViewModelTests-macOS"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -703,6 +708,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "es.estebantorr.RxViewModelTests-macOS"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -803,7 +809,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; PRODUCT_BUNDLE_IDENTIFIER = "es.estebantorr.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/tmp_Example.app/tmp_Example"; + SWIFT_VERSION = 3.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Demo.app/Demo"; }; name = Debug; }; @@ -816,7 +823,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; PRODUCT_BUNDLE_IDENTIFIER = "es.estebantorr.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/tmp_Example.app/tmp_Example"; + SWIFT_VERSION = 3.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Demo.app/Demo"; }; name = Release; }; diff --git a/Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme b/Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme index 1ec6561..c2d609a 100644 --- a/Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme +++ b/Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme @@ -1,6 +1,6 @@ Bool { - // Override point for customization after application launch. - return true - } - - func applicationWillResignActive(application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - } - - func applicationDidEnterBackground(application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } - - func applicationWillEnterForeground(application: UIApplication) { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. - } - - func applicationDidBecomeActive(application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - } - - func applicationWillTerminate(application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - - + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + return true + } } diff --git a/Demo/Demo/ViewController.swift b/Demo/Demo/ViewController.swift index 49cd332..de6f024 100644 --- a/Demo/Demo/ViewController.swift +++ b/Demo/Demo/ViewController.swift @@ -9,16 +9,8 @@ import UIKit class ViewController: UIViewController { - override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. - } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. } - } diff --git a/Demo/Podfile b/Demo/Podfile index b53895b..ec0814f 100644 --- a/Demo/Podfile +++ b/Demo/Podfile @@ -1,6 +1,7 @@ source 'https://github.com/CocoaPods/Specs.git' use_frameworks! +inhibit_all_warnings! # Test Libraries def test_pods @@ -36,19 +37,4 @@ target 'RxViewModelTests-macOS' do library test_pods -end - -# Hack to fix testability until cocoapods gets an update -post_install do |installer| - installer.pods_project.targets.each do |target| - target.build_configurations.each do |config| - if config.name == 'Debug' - config.build_settings['ENABLE_TESTABILITY'] = 'YES' - - if target.name.include? "RxViewModel-" - config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'YES' - end - end - end - end -end +end \ No newline at end of file diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index c2b1feb..7ab4bd7 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -1,9 +1,9 @@ PODS: - - Nimble (4.1.0) - - Quick (0.9.2) - - RxSwift (2.5.0) - - RxViewModel (3.1.4): - - RxSwift (~> 2.5) + - Nimble (7.0.1) + - Quick (1.1.0) + - RxSwift (3.4.0) + - RxViewModel (4.0.0): + - RxSwift (~> 3.4) DEPENDENCIES: - Nimble @@ -15,11 +15,11 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - Nimble: 97a0a4cae5124c117115634b2d055d8c97d0af19 - Quick: 18d057bc66451eedd5d1c8dc99ba2a5db6e60226 - RxSwift: 402b41a50e922a0368fc14cb3bc9f4427920e8ae - RxViewModel: cb396b511b9b94bd7a253b86b6b5a65e2b36043e + Nimble: 657d000e11df8aebe27cdaf9d244de7f30ed87f7 + Quick: dafc587e21eed9f4cab3249b9f9015b0b7a7f71d + RxSwift: 3789a1af753002a14edecdb698a2424624296a9c + RxViewModel: f306c2963ff6978705c07a5c299abc5cc9f9a982 -PODFILE CHECKSUM: 3783e79cefc5ffb9fe32d2e6f6d48bf5ec74e93f +PODFILE CHECKSUM: 5b740ff0f8e82b1a56bee6decd0acad5bd6013b9 -COCOAPODS: 1.0.1 +COCOAPODS: 1.2.1 diff --git a/Demo/Tests/Tests.swift b/Demo/Tests/Tests.swift index d2bbc95..b861893 100644 --- a/Demo/Tests/Tests.swift +++ b/Demo/Tests/Tests.swift @@ -41,11 +41,11 @@ class RxViewModelSpec: QuickSpec { } var nextSteps = 0 - vm.didBecomeActive.subscribeNext { model in + vm.didBecomeActive.subscribe(onNext: { model in expect(model).to(equal(vm)) nextSteps += 1 - }.addDisposableTo(self.disposable) + }).disposed(by: self.disposable) expect(nextSteps).to(equal(0)) @@ -74,17 +74,18 @@ class RxViewModelSpec: QuickSpec { var completed = false let input = Observable.create { o -> Disposable in - o.on(.Next("1")) - o.on(.Next("2")) + o.on(.next("1")) + o.on(.next("2")) - return AnonymousDisposable {} + return Disposables.create { } } as Observable - vm.forwardSignalWhileActive(input).subscribe( onNext: { value in - values.append(value!) + vm.forwardSignalWhileActive(input).subscribe(onNext: { value in + guard let value = value else { return } + values.append(value) }, onError: { _ in }, onCompleted: { completed = true - }).addDisposableTo(self.disposable) + }).disposed(by: self.disposable) var expectedValues = ["1", "2"] expect(values).to(equal(expectedValues)) @@ -112,19 +113,21 @@ class RxViewModelSpec: QuickSpec { var values = [String]() var completed = false let subject = ReplaySubject.create(bufferSize: 5) - subject.on(.Next("0")) + subject.on(.next("0")) - vm.throttleSignalWhileInactive(subject).subscribe( onNext: { value in - values.append(value) - }, onError: { _ in }, onCompleted: { - completed = true - }).addDisposableTo(self.disposable) + vm.throttleSignalWhileInactive(subject) + .observeOn(MainScheduler.instance) + .subscribe(onNext: { value in + values.append(value) + }, onError: { _ in }, onCompleted: { + completed = true + }).disposed(by: self.disposable) var expectedValues = ["0"] expect(values).to(equal(expectedValues)) expect(completed).to(beFalsy()) - subject.on(.Next("1")) + subject.on(.next("1")) expectedValues = ["0", "1"] expect(values).to(equal(expectedValues)) expect(completed).to(beFalsy()) @@ -132,8 +135,8 @@ class RxViewModelSpec: QuickSpec { vm.active = false // Since the VM is inactive, these events should be throttled. - subject.on(.Next("2")) - subject.on(.Next("3")) + subject.on(.next("2")) + subject.on(.next("3")) expect(values).to(equal(expectedValues)) expect(completed).to(beFalsy()) @@ -143,7 +146,7 @@ class RxViewModelSpec: QuickSpec { expect(completed).to(beFalsy()) // After reactivating, we should still get this event. - subject.on(.Next("4")) + subject.on(.next("4")) vm.active = true expectedValues = ["0", "1", "3", "4"] @@ -151,16 +154,16 @@ class RxViewModelSpec: QuickSpec { expect(completed).to(beFalsy()) // And now new events should be instant. - subject.on(.Next("5")) + subject.on(.next("5")) expectedValues = ["0", "1", "3", "4", "5"] expect(values).to(equal(expectedValues)) expect(completed).to(beFalsy()) - subject.on(.Completed) + subject.on(.completed) expect(values).to(equal(expectedValues)) expect(completed).to(beTruthy()) } } -} \ No newline at end of file +} diff --git a/Gemfile b/Gemfile index cb92d90..94bb1f8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.3.1' +ruby '2.4.1' # The Cocoa library package manager. gem 'cocoapods' diff --git a/Gemfile.lock b/Gemfile.lock index 128d858..f75d6e8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,59 +1,62 @@ GIT remote: https://github.com/paweldudek/danger-swiftlint - revision: 693daa326f99ebf3b1517ab13f6a954b6d4620d4 + revision: 2ae416a243f3c3d35cbe465e66a4c39e529eb423 branch: master specs: - danger-swiftlint (0.1.0) + danger-swiftlint (0.1.2) danger GEM remote: https://rubygems.org/ specs: - activesupport (5.0.0) - concurrent-ruby (~> 1.0, >= 1.0.2) + CFPropertyList (2.3.5) + activesupport (4.2.8) i18n (~> 0.7) minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.4.0) - backports (3.6.8) - claide (1.0.0) + backports (3.8.0) + claide (1.0.2) clamp (0.6.5) - cocoapods (1.0.1) - activesupport (>= 4.0.2) - claide (>= 1.0.0, < 2.0) - cocoapods-core (= 1.0.1) - cocoapods-deintegrate (>= 1.0.0, < 2.0) - cocoapods-downloader (>= 1.0.0, < 2.0) + cocoapods (1.2.1) + activesupport (>= 4.0.2, < 5) + claide (>= 1.0.1, < 2.0) + cocoapods-core (= 1.2.1) + cocoapods-deintegrate (>= 1.0.1, < 2.0) + cocoapods-downloader (>= 1.1.3, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.0.0, < 2.0) - cocoapods-try (>= 1.0.0, < 2.0) - colored (~> 1.2) + cocoapods-trunk (>= 1.2.0, < 2.0) + cocoapods-try (>= 1.1.0, < 2.0) + colored2 (~> 3.1) escape (~> 0.0.4) - fourflusher (~> 0.3.0) - molinillo (~> 0.4.5) + fourflusher (~> 2.0.1) + gh_inspector (~> 1.0) + molinillo (~> 0.5.7) nap (~> 1.0) - xcodeproj (>= 1.1.0, < 2.0) - cocoapods-core (1.0.1) - activesupport (>= 4.0.2) + ruby-macho (~> 1.1) + xcodeproj (>= 1.4.4, < 2.0) + cocoapods-core (1.2.1) + activesupport (>= 4.0.2, < 5) fuzzy_match (~> 2.0.4) nap (~> 1.0) - cocoapods-deintegrate (1.0.0) - cocoapods-downloader (1.0.1) + cocoapods-deintegrate (1.0.1) + cocoapods-downloader (1.1.3) cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) cocoapods-stats (1.0.0) - cocoapods-trunk (1.0.0) + cocoapods-trunk (1.2.0) nap (>= 0.8, < 2.0) netrc (= 0.7.8) - cocoapods-try (1.0.0) + cocoapods-try (1.1.0) colored (1.2) + colored2 (3.1.2) colorize (0.8.1) - concurrent-ruby (1.0.2) - cork (0.1.0) - colored (~> 1.2) + cork (0.3.0) + colored2 (~> 3.1) danger (0.8.5) claide (~> 1.0) colored (~> 1.2) @@ -63,78 +66,73 @@ GEM octokit (~> 4.2) redcarpet (~> 3.3) terminal-table (~> 1) - descendants_tracker (0.0.4) - thread_safe (~> 0.3, >= 0.3.1) escape (0.0.4) - ethon (0.9.0) + ethon (0.10.1) ffi (>= 1.3.0) - faraday (0.9.2) + faraday (0.12.1) multipart-post (>= 1.2, < 3) - faraday_middleware (0.10.0) - faraday (>= 0.7.4, < 0.10) - ffi (1.9.13) - fourflusher (0.3.2) + faraday-http-cache (2.0.0) + faraday (~> 0.8) + faraday_middleware (0.11.0.1) + faraday (>= 0.7.4, < 1.0) + ffi (1.9.18) + fourflusher (2.0.1) fuzzy_match (2.0.4) - gh (0.14.0) - addressable + gh (0.15.1) + addressable (~> 2.4.0) backports faraday (~> 0.8) multi_json (~> 1.0) - net-http-persistent (>= 2.7) + net-http-persistent (~> 2.9) net-http-pipeline + gh_inspector (1.0.3) git (1.3.0) - github_api (0.14.3) - addressable (~> 2.4.0) - descendants_tracker (~> 0.0.4) - faraday (~> 0.8, < 0.10) - hashie (>= 3.4) - oauth2 (~> 1.0.0) - github_changelog_generator (1.13.0) - colorize (~> 0.7) - github_api (~> 0.12) + github_changelog_generator (1.14.3) + activesupport + faraday-http-cache + multi_json + octokit (~> 4.6) + rainbow (>= 2.1) rake (>= 10.0) - hashie (3.4.4) + retriable (~> 2.1) highline (1.7.8) - i18n (0.7.0) - json (2.0.1) - jwt (1.5.4) + i18n (0.8.4) + json (2.1.0) label (1.0.0) launchy (2.4.3) addressable (~> 2.3) - minitest (5.9.0) - molinillo (0.4.5) + minitest (5.10.2) + molinillo (0.5.7) multi_json (1.12.1) - multi_xml (0.5.5) multipart-post (2.0.0) + nanaimo (0.2.3) nap (1.1.0) net-http-persistent (2.9.4) net-http-pipeline (1.0.1) netrc (0.7.8) - oauth2 (1.0.0) - faraday (>= 0.8, < 0.10) - jwt (~> 1.0) - multi_json (~> 1.3) - multi_xml (~> 0.5) - rack (~> 1.2) - octokit (4.3.0) - sawyer (~> 0.7.0, >= 0.5.3) + octokit (4.7.0) + sawyer (~> 0.8.0, >= 0.5.3) pusher-client (0.6.2) json websocket (~> 1.0) - rack (1.6.4) - rake (11.2.2) - redcarpet (3.3.4) - rouge (1.11.1) - sawyer (0.7.0) - addressable (>= 2.3.5, < 2.5) - faraday (~> 0.8, < 0.10) + rainbow (2.2.2) + rake + rake (12.0.0) + redcarpet (3.4.0) + retriable (2.1.0) + rouge (2.0.7) + ruby-macho (1.1.0) + sawyer (0.8.1) + addressable (>= 2.3.5, < 2.6) + faraday (~> 0.8, < 1.0) synx (0.2.1) clamp (~> 0.6) colorize (~> 0.7) xcodeproj (~> 1.0) - terminal-table (1.6.0) - thread_safe (0.3.5) - travis (1.8.2) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thread_safe (0.3.6) + travis (1.8.8) backports faraday (~> 0.9) faraday_middleware (~> 0.9, >= 0.9.1) @@ -145,15 +143,17 @@ GEM typhoeus (~> 0.6, >= 0.6.8) typhoeus (0.8.0) ethon (>= 0.8.0) - tzinfo (1.2.2) + tzinfo (1.2.3) thread_safe (~> 0.1) - websocket (1.2.3) - xcodeproj (1.1.0) - activesupport (>= 3) - claide (>= 1.0.0, < 2.0) - colored (~> 1.2) - xcpretty (0.2.2) - rouge (~> 1.8) + unicode-display_width (1.3.0) + websocket (1.2.4) + xcodeproj (1.5.0) + CFPropertyList (~> 2.3.3) + claide (>= 1.0.2, < 2.0) + colored2 (~> 3.1) + nanaimo (~> 0.2.3) + xcpretty (0.2.8) + rouge (~> 2.0.7) PLATFORMS ruby @@ -172,7 +172,7 @@ DEPENDENCIES xcpretty RUBY VERSION - ruby 2.3.1p112 + ruby 2.4.1p111 BUNDLED WITH - 1.12.5 + 1.15.1 diff --git a/Rakefile b/Rakefile index c9795e0..c218bb3 100644 --- a/Rakefile +++ b/Rakefile @@ -26,7 +26,7 @@ def sdks return { ios: 'iphonesimulator', macos: 'macosx', - tvos: 'appletvsimulator9.2' + tvos: 'appletvsimulator10.2' } end diff --git a/RxViewModel.podspec b/RxViewModel.podspec index d15910d..d5852e7 100644 --- a/RxViewModel.podspec +++ b/RxViewModel.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "RxViewModel" - s.version = "3.1.4" + s.version = "4.0.0" s.summary = "`RxViewModel` is the marriage between `MVVM` and `Rx` extensions. A blatant «imitation» of `ReactiveViewModel` using `RxCocoa`." s.description = <<-DESC `RxViewModel` is the marriage between `MVVM` and `Rx` extensions @@ -25,6 +25,6 @@ Long story short: a blatant «imitation» of `ReactiveViewModel `using `RxCocoa` s.requires_arc = true s.source_files = 'Source/*.swift', 'Source/Categories/*.swift' - s.dependency 'RxSwift', '~> 2.5' + s.dependency 'RxSwift', '~> 3.4' s.frameworks = 'Foundation' end diff --git a/RxViewModel.xcodeproj/project.pbxproj b/RxViewModel.xcodeproj/project.pbxproj index d3e5807..d846f26 100644 --- a/RxViewModel.xcodeproj/project.pbxproj +++ b/RxViewModel.xcodeproj/project.pbxproj @@ -117,6 +117,7 @@ TargetAttributes = { 1168B9AF1D2E081800784841 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0830; }; }; }; @@ -203,6 +204,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -244,6 +246,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.3; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -265,6 +268,7 @@ PRODUCT_BUNDLE_IDENTIFIER = es.estebantorr.RxViewModel; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -282,6 +286,7 @@ PRODUCT_BUNDLE_IDENTIFIER = es.estebantorr.RxViewModel; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Source/Categories/Observable_Operations.swift b/Source/Categories/Observable_Operations.swift index 9c42269..62c31e6 100644 --- a/Source/Categories/Observable_Operations.swift +++ b/Source/Categories/Observable_Operations.swift @@ -36,16 +36,16 @@ import RxSwift returns `true`. Completion and errors are always forwarded immediately. */ extension ObservableType { - public func throttle(interval: NSTimeInterval, valuesPassingTest predicate: (E) -> Bool) -> Observable { - return Observable.create { (o: AnyObserver) -> Disposable in + public func throttle(_ interval: TimeInterval, valuesPassingTest predicate: @escaping (E) -> Bool) -> Observable { + return Observable.create { (obs: AnyObserver) -> Disposable in let disposable = CompositeDisposable() - let scheduler = ConcurrentDispatchQueueScheduler(globalConcurrentQueueQOS: .Default) + let scheduler = ConcurrentDispatchQueueScheduler(qos: .default) let nextDisposable = SerialDisposable() var hasNextValue = false var nextValue: E? let parent = self.asObservable() - let subscriptionDisposable = parent.subscribeNext { + let subscriptionDisposable = parent.subscribe(onNext: { /** Disposes the «last» `next` subscription if there was a previous value it gets flushed to the observable `o`. @@ -53,23 +53,22 @@ extension ObservableType { - parameter send: `Bool` flag indicating where or not the `next` value should be «flushed» to the `observable` `o` or not. */ - func flushNext(send: Bool) -> Void { + func flushNext(_ send: Bool) { nextDisposable.dispose() - guard let nV = nextValue where hasNextValue == true && send == true - else { return } + guard let nV = nextValue, hasNextValue, send else { return } nextValue = nil hasNextValue = false - - o.on(.Next(nV)) + + obs.on(.next(nV)) } let shouldThrottle = predicate($0) flushNext(false) if !shouldThrottle { - o.on(.Next($0)) + obs.on(.next($0)) return } @@ -79,16 +78,16 @@ extension ObservableType { let flush = flushNext let d = Observable.timer(interval, scheduler: scheduler) - .subscribeNext { _ in - flush(true) - } + .subscribe(onNext: { _ in + flush(true) + }) - disposable.addDisposable(d) - } - - disposable.addDisposable(subscriptionDisposable) + _ = disposable.insert(d) + }) + + _ = disposable.insert(subscriptionDisposable) return disposable } } -} \ No newline at end of file +} diff --git a/Source/RxViewModel.swift b/Source/RxViewModel.swift index da01360..780bb4a 100644 --- a/Source/RxViewModel.swift +++ b/Source/RxViewModel.swift @@ -18,7 +18,7 @@ user-presentable. */ public class RxViewModel: NSObject { // MARK: Constants - let throttleTime: NSTimeInterval = 2 + let throttleTime: TimeInterval = 2 // MARK: Properties /// Scope dispose to avoid leaking @@ -37,7 +37,7 @@ public class RxViewModel: NSObject { if newValue == _active { return } _active = newValue - self.activeObservable.on(.Next(_active)) + self.activeObservable.on(.next(_active)) } } @@ -90,38 +90,38 @@ public class RxViewModel: NSObject { `signal`, and completes when the receiver is deallocated. If `signal` sends an error at any point, the returned signal will error out as well. */ - public func forwardSignalWhileActive(observable: Observable) -> Observable { + public func forwardSignalWhileActive(_ observable: Observable) -> Observable { let signal = self.activeObservable - return Observable.create { (o: AnyObserver) -> Disposable in + return Observable.create { (obs: AnyObserver) -> Disposable in let disposable = CompositeDisposable() var signalDisposable: Disposable? = nil - var disposeKey: Bag.KeyType? + var disposeKey: CompositeDisposable.DisposeKey? let activeDisposable = signal.subscribe( onNext: { active in if active == true { signalDisposable = observable.subscribe( onNext: { value in - o.on(.Next(value)) + obs.on(.next(value)) }, onError: { error in - o.on(.Error(error)) + obs.on(.error(error)) }, onCompleted: {}) - if let sd = signalDisposable { disposeKey = disposable.addDisposable(sd) } + if let sd = signalDisposable { disposeKey = disposable.insert(sd) } } else { if let sd = signalDisposable { sd.dispose() if let dk = disposeKey { - disposable.removeDisposable(dk) + disposable.remove(for: dk) } } } }, onError: { error in - o.on(.Error(error)) + obs.on(.error(error)) }, onCompleted: { - o.on(.Completed) + obs.on(.completed) }) - - disposable.addDisposable(activeDisposable) + + _ = disposable.insert(activeDisposable) return disposable } @@ -141,25 +141,24 @@ public class RxViewModel: NSObject { receiver is inactive), and completes when `observable` completes or the receiver is deallocated. */ - public func throttleSignalWhileInactive(observable: Observable) -> Observable { -// observable.replay(1) + public func throttleSignalWhileInactive(_ observable: Observable) -> Observable { let result = ReplaySubject.create(bufferSize: 1) - let activeSignal = self.activeObservable.takeUntil(Observable.create { (o: AnyObserver) -> Disposable in - observable.subscribeCompleted { + let activeSignal = self.activeObservable.takeUntil(Observable.create { (_: AnyObserver) -> Disposable in + observable.subscribe(onCompleted: { defer { result.dispose() } - result.on(.Completed) - } + result.on(.completed) + }) }) - let _ = Observable.combineLatest(activeSignal, observable) { (active, o) -> (Bool?, T) in (active, o) } - .throttle(throttleTime) { (active: Bool?, value: T) -> Bool in + _ = Observable.combineLatest(activeSignal, observable) { (active, obs) -> (Bool?, T) in (active, obs) } + .throttle(throttleTime) { (active: Bool?, _: T) -> Bool in return active == false }.subscribe(onNext: { (value: (Bool?, T)) in - result.on(.Next(value.1)) + result.on(.next(value.1)) }, onError: { _ in }, onCompleted: { - result.on(.Completed) + result.on(.completed) }) return result