Skip to content

Commit fc751bd

Browse files
committed
Move all code base to Swift 3 and make tests pass 🎉
1 parent 607ff68 commit fc751bd

File tree

11 files changed

+238
-199
lines changed

11 files changed

+238
-199
lines changed

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [Unreleased](https://github.com/RxSwiftCommunity/RxViewModel/tree/HEAD)
4+
- Support for Swift 3 & 4 [\#45](https://github.com/RxSwiftCommunity/RxViewModel/pull/45) ([freak4pc](https://github.com/freak4pc))
45

56
[Full Changelog](https://github.com/RxSwiftCommunity/RxViewModel/compare/3.1.3...HEAD)
67

‎Demo/Demo.xcodeproj/project.pbxproj‎

Lines changed: 175 additions & 106 deletions
Large diffs are not rendered by default.

‎Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0830"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

‎Demo/Demo.xcodeproj/xcshareddata/xcschemes/RxViewModelTests-macOS.xcscheme‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0830"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

‎Demo/Demo.xcodeproj/xcshareddata/xcschemes/RxViewModelTests-tvOS.xcscheme‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0830"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

‎Demo/Demo/AppDelegate.swift‎

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,9 @@ import UIKit
1010

1111
@UIApplicationMain
1212
class AppDelegate: UIResponder, UIApplicationDelegate {
13+
var window: UIWindow?
1314

14-
var window: UIWindow?
15-
16-
17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18-
// Override point for customization after application launch.
19-
return true
20-
}
21-
22-
func applicationWillResignActive(application: UIApplication) {
23-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24-
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25-
}
26-
27-
func applicationDidEnterBackground(application: UIApplication) {
28-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30-
}
31-
32-
func applicationWillEnterForeground(application: UIApplication) {
33-
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34-
}
35-
36-
func applicationDidBecomeActive(application: UIApplication) {
37-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38-
}
39-
40-
func applicationWillTerminate(application: UIApplication) {
41-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42-
}
43-
44-
15+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
16+
return true
17+
}
4518
}

‎Demo/Demo/ViewController.swift‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,8 @@
99
import UIKit
1010

1111
class ViewController: UIViewController {
12-
1312
override func viewDidLoad() {
1413
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
16-
}
17-
18-
override func didReceiveMemoryWarning() {
19-
super.didReceiveMemoryWarning()
20-
// Dispose of any resources that can be recreated.
2114
}
2215

23-
2416
}

‎Demo/Tests/Tests.swift‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class RxViewModelSpec: QuickSpec {
4141
}
4242

4343
var nextSteps = 0
44-
vm.didBecomeActive.subscribeNext { model in
44+
vm.didBecomeActive.subscribe(onNext: { model in
4545
expect(model).to(equal(vm))
4646

4747
nextSteps += 1
48-
}.addDisposableTo(self.disposable)
48+
}).disposed(by: self.disposable)
4949

5050
expect(nextSteps).to(equal(0))
5151

@@ -74,17 +74,17 @@ class RxViewModelSpec: QuickSpec {
7474
var completed = false
7575

7676
let input = Observable.create { o -> Disposable in
77-
o.on(.Next("1"))
78-
o.on(.Next("2"))
77+
o.on(.next("1"))
78+
o.on(.next("2"))
7979

80-
return AnonymousDisposable {}
80+
return Disposables.create { }
8181
} as Observable<String?>
8282

83-
vm.forwardSignalWhileActive(input).subscribe( onNext: { value in
83+
vm.forwardSignalWhileActive(input).subscribe(onNext: { value in
8484
values.append(value!)
8585
}, onError: { _ in }, onCompleted: {
8686
completed = true
87-
}).addDisposableTo(self.disposable)
87+
}).disposed(by: self.disposable)
8888

8989
var expectedValues = ["1", "2"]
9090
expect(values).to(equal(expectedValues))
@@ -112,28 +112,28 @@ class RxViewModelSpec: QuickSpec {
112112
var values = [String]()
113113
var completed = false
114114
let subject = ReplaySubject<String>.create(bufferSize: 5)
115-
subject.on(.Next("0"))
115+
subject.on(.next("0"))
116116

117117
vm.throttleSignalWhileInactive(subject).subscribe( onNext: { value in
118118
values.append(value)
119119
}, onError: { _ in }, onCompleted: {
120120
completed = true
121-
}).addDisposableTo(self.disposable)
121+
}).disposed(by: self.disposable)
122122

123123
var expectedValues = ["0"]
124124
expect(values).to(equal(expectedValues))
125125
expect(completed).to(beFalsy())
126126

127-
subject.on(.Next("1"))
127+
subject.on(.next("1"))
128128
expectedValues = ["0", "1"]
129129
expect(values).to(equal(expectedValues))
130130
expect(completed).to(beFalsy())
131131

132132
vm.active = false
133133

134134
// Since the VM is inactive, these events should be throttled.
135-
subject.on(.Next("2"))
136-
subject.on(.Next("3"))
135+
subject.on(.next("2"))
136+
subject.on(.next("3"))
137137

138138
expect(values).to(equal(expectedValues))
139139
expect(completed).to(beFalsy())
@@ -143,24 +143,24 @@ class RxViewModelSpec: QuickSpec {
143143
expect(completed).to(beFalsy())
144144

145145
// After reactivating, we should still get this event.
146-
subject.on(.Next("4"))
146+
subject.on(.next("4"))
147147
vm.active = true
148148

149149
expectedValues = ["0", "1", "3", "4"]
150150
expect(values).toEventually(equal(expectedValues))
151151
expect(completed).to(beFalsy())
152152

153153
// And now new events should be instant.
154-
subject.on(.Next("5"))
154+
subject.on(.next("5"))
155155

156156
expectedValues = ["0", "1", "3", "4", "5"]
157157
expect(values).to(equal(expectedValues))
158158
expect(completed).to(beFalsy())
159159

160-
subject.on(.Completed)
160+
subject.on(.completed)
161161

162162
expect(values).to(equal(expectedValues))
163163
expect(completed).to(beTruthy())
164164
}
165165
}
166-
}
166+
}

‎RxViewModel.xcodeproj/project.pbxproj‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
TargetAttributes = {
118118
1168B9AF1D2E081800784841 = {
119119
CreatedOnToolsVersion = 7.3.1;
120+
LastSwiftMigration = 0830;
120121
};
121122
};
122123
};
@@ -265,6 +266,7 @@
265266
PRODUCT_BUNDLE_IDENTIFIER = es.estebantorr.RxViewModel;
266267
PRODUCT_NAME = "$(TARGET_NAME)";
267268
SKIP_INSTALL = YES;
269+
SWIFT_VERSION = 3.0;
268270
};
269271
name = Debug;
270272
};
@@ -282,6 +284,7 @@
282284
PRODUCT_BUNDLE_IDENTIFIER = es.estebantorr.RxViewModel;
283285
PRODUCT_NAME = "$(TARGET_NAME)";
284286
SKIP_INSTALL = YES;
287+
SWIFT_VERSION = 3.0;
285288
};
286289
name = Release;
287290
};

‎Source/Categories/Observable_Operations.swift‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,39 @@ import RxSwift
3636
returns `true`. Completion and errors are always forwarded immediately.
3737
*/
3838
extension ObservableType {
39-
public func throttle(interval: NSTimeInterval, valuesPassingTest predicate: (E) -> Bool) -> Observable<E> {
39+
public func throttle(_ interval: TimeInterval, valuesPassingTest predicate: @escaping (E) -> Bool) -> Observable<E> {
4040
return Observable.create { (o: AnyObserver<E>) -> Disposable in
4141
let disposable = CompositeDisposable()
42-
let scheduler = ConcurrentDispatchQueueScheduler(globalConcurrentQueueQOS: .Default)
42+
let scheduler = ConcurrentDispatchQueueScheduler(qos: .default)
4343
let nextDisposable = SerialDisposable()
4444
var hasNextValue = false
4545
var nextValue: E?
4646
let parent = self.asObservable()
4747

48-
let subscriptionDisposable = parent.subscribeNext {
48+
let subscriptionDisposable = parent.subscribe(onNext: {
4949
/**
5050
Disposes the «last» `next` subscription if there was a previous value it gets
5151
flushed to the observable `o`.
5252

5353
- parameter send: `Bool` flag indicating where or not the `next` value should be
5454
«flushed» to the `observable` `o` or not.
5555
*/
56-
func flushNext(send: Bool) -> Void {
56+
func flushNext(_ send: Bool) -> Void {
5757
nextDisposable.dispose()
5858

59-
guard let nV = nextValue where hasNextValue == true && send == true
60-
else { return }
59+
guard let nV = nextValue, hasNextValue, send else { return }
6160

6261
nextValue = nil
6362
hasNextValue = false
64-
65-
o.on(.Next(nV))
63+
64+
o.on(.next(nV))
6665
}
6766

6867
let shouldThrottle = predicate($0)
6968
flushNext(false)
7069

7170
if !shouldThrottle {
72-
o.on(.Next($0))
71+
o.on(.next($0))
7372

7473
return
7574
}
@@ -79,16 +78,17 @@ extension ObservableType {
7978

8079
let flush = flushNext
8180
let d = Observable<Int64>.timer(interval, scheduler: scheduler)
82-
.subscribeNext { _ in
83-
flush(true)
84-
}
81+
.subscribe(onNext: { _ in
82+
flush(true)
83+
})
8584

86-
disposable.addDisposable(d)
87-
}
88-
89-
disposable.addDisposable(subscriptionDisposable)
85+
_ = disposable.insert(d)
86+
})
87+
88+
89+
_ = disposable.insert(subscriptionDisposable)
9090

9191
return disposable
9292
}
9393
}
94-
}
94+
}

0 commit comments

Comments
 (0)