Skip to content

Commit 370f312

Browse files
Merge pull request #4 from patr1ck/master
Updates to work with Swift 1.2 / Xcode 6.3
2 parents 1b89649 + 046bc36 commit 370f312

9 files changed

+28
-29
lines changed

ReactiveSwiftFlickrSearch/AppDelegate.swift

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import UIKit
1111
@UIApplicationMain
1212
class AppDelegate: UIResponder, UIApplicationDelegate {
1313

14-
var window: UIWindow!
14+
var window: UIWindow?
1515

1616
var navigationController: UINavigationController!
1717

18-
19-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
20-
18+
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
2119
navigationController = UINavigationController()
2220
navigationController.navigationBar.barTintColor = UIColor.darkGrayColor()
2321
navigationController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
@@ -30,8 +28,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3028

3129

3230
window = UIWindow(frame: UIScreen.mainScreen().bounds)
33-
window.rootViewController = navigationController
34-
window.makeKeyAndVisible()
31+
window!.rootViewController = navigationController
32+
window!.makeKeyAndVisible()
3533

3634
return true
3735
}

ReactiveSwiftFlickrSearch/Model/FlickrSearchImpl.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FlickrSearchImpl : NSObject, FlickrSearch, OFFlickrAPIRequestDelegate {
3333
func flickrSearchSignal(searchString: String) -> RACSignal {
3434

3535
func photosFromDictionary (response: NSDictionary) -> FlickrSearchResults {
36-
let photoArray = response.valueForKeyPath("photos.photo") as [[String: String]]
36+
let photoArray = response.valueForKeyPath("photos.photo") as! [[String: String]]
3737
let photos = photoArray.map {
3838
(photoDict) -> FlickrPhoto in
3939
let url = self.flickrContext.photoSourceURLFromDictionary(photoDict, size: OFFlickrSmallSize)
@@ -55,13 +55,13 @@ class FlickrSearchImpl : NSObject, FlickrSearch, OFFlickrAPIRequestDelegate {
5555
arguments: ["photo_id": photoId]) {
5656
// String is not AnyObject?
5757
(response: NSDictionary) -> NSString in
58-
return response.valueForKeyPath("photo.total") as NSString
58+
return response.valueForKeyPath("photo.total") as! NSString
5959
}
6060

6161
let commentsSignal = signalFromAPIMethod("flickr.photos.getInfo",
6262
arguments: ["photo_id": photoId]) {
6363
(response: NSDictionary) -> NSString in
64-
return response.valueForKeyPath("photo.comments._text") as NSString
64+
return response.valueForKeyPath("photo.comments._text") as! NSString
6565
}
6666

6767
return RACSignalEx.combineLatestAs([favouritesSignal, commentsSignal]) {
@@ -89,7 +89,7 @@ class FlickrSearchImpl : NSObject, FlickrSearch, OFFlickrAPIRequestDelegate {
8989

9090
sucessSignal
9191
// filter to only include responses from this request
92-
.filterAs { (tuple: RACTuple) -> Bool in tuple.first as NSObject == flickrRequest }
92+
.filterAs { (tuple: RACTuple) -> Bool in tuple.first as! NSObject == flickrRequest }
9393
// extract the second tuple argument, which is the response dictionary
9494
.mapAs { (tuple: RACTuple) -> AnyObject in tuple.second }
9595
// transform with the given function

ReactiveSwiftFlickrSearch/Util/RACSignal+Extensions.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ extension RACSignal {
1414
func subscribeNextAs<T>(nextClosure:(T) -> ()) -> () {
1515
self.subscribeNext {
1616
(next: AnyObject!) -> () in
17-
let nextAsT = next! as T
17+
let nextAsT = next! as! T
1818
nextClosure(nextAsT)
1919
}
2020
}
2121

2222
func mapAs<T: AnyObject, U: AnyObject>(mapClosure:(T) -> U) -> RACSignal {
2323
return self.map {
2424
(next: AnyObject!) -> AnyObject! in
25-
let nextAsT = next as T
25+
let nextAsT = next as! T
2626
return mapClosure(nextAsT)
2727
}
2828
}
2929

3030
func filterAs<T: AnyObject>(filterClosure:(T) -> Bool) -> RACSignal {
3131
return self.filter {
3232
(next: AnyObject!) -> Bool in
33-
let nextAsT = next as T
33+
let nextAsT = next as! T
3434
return filterClosure(nextAsT)
3535
}
3636
}
3737

3838
func doNextAs<T: AnyObject>(nextClosure:(T) -> ()) -> RACSignal {
3939
return self.doNext {
4040
(next: AnyObject!) -> () in
41-
let nextAsT = next as T
41+
let nextAsT = next as! T
4242
nextClosure(nextAsT)
4343
}
4444
}
@@ -48,7 +48,7 @@ class RACSignalEx {
4848
class func combineLatestAs<T, U, R: AnyObject>(signals:[RACSignal], reduce:(T,U) -> R) -> RACSignal {
4949
return RACSignal.combineLatest(signals).mapAs {
5050
(tuple: RACTuple) -> R in
51-
return reduce(tuple.first as T, tuple.second as U)
51+
return reduce(tuple.first as! T, tuple.second as! U)
5252
}
5353
}
5454
}

ReactiveSwiftFlickrSearch/Util/TableViewBindingHelper.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class TableViewBindingHelper: NSObject, UITableViewDataSource, UITableViewDelega
3535
let nib = UINib(nibName: nibName, bundle: nil)
3636

3737
// create an instance of the template cell and register with the table view
38-
templateCell = nib.instantiateWithOwner(nil, options: nil)[0] as UITableViewCell
38+
templateCell = nib.instantiateWithOwner(nil, options: nil)[0] as! UITableViewCell
3939
tableView.registerNib(nib, forCellReuseIdentifier: templateCell.reuseIdentifier!)
4040

4141
super.init()
4242

4343
sourceSignal.subscribeNext {
4444
(d:AnyObject!) -> () in
45-
self.data = d as [AnyObject]
45+
self.data = d as! [AnyObject]
4646
self.tableView.reloadData()
4747
}
4848

@@ -58,7 +58,7 @@ class TableViewBindingHelper: NSObject, UITableViewDataSource, UITableViewDelega
5858

5959
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
6060
let item: AnyObject = data[indexPath.row]
61-
let cell = tableView.dequeueReusableCellWithIdentifier(templateCell.reuseIdentifier!) as UITableViewCell
61+
let cell = tableView.dequeueReusableCellWithIdentifier(templateCell.reuseIdentifier!) as! UITableViewCell
6262
if let reactiveView = cell as? ReactiveView {
6363
reactiveView.bindViewModel(item)
6464
}

ReactiveSwiftFlickrSearch/View/FlickrSearchViewController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class FlickrSearchViewController: UIViewController {
4141

4242
searchTextField.rac_textSignal() ~> RAC(viewModel, "searchText")
4343

44-
viewModel.executeSearch.executing.NOT() ~> RAC(loadingIndicator, "hidden")
44+
viewModel.executeSearch!.executing.NOT() ~> RAC(loadingIndicator, "hidden")
4545

46-
viewModel.executeSearch.executing ~> RAC(UIApplication.sharedApplication(), "networkActivityIndicatorVisible")
46+
viewModel.executeSearch!.executing ~> RAC(UIApplication.sharedApplication(), "networkActivityIndicatorVisible")
4747

4848
searchButton.rac_command = viewModel.executeSearch
4949

@@ -60,7 +60,7 @@ class FlickrSearchViewController: UIViewController {
6060
func hideKeyboard(any: AnyObject!) {
6161
self.searchTextField.resignFirstResponder()
6262
}
63-
viewModel.executeSearch.executionSignals.subscribeNext(hideKeyboard)
63+
viewModel.executeSearch!.executionSignals.subscribeNext(hideKeyboard)
6464
}
6565

6666
}

ReactiveSwiftFlickrSearch/View/RecentSearchItemTableViewCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RecentSearchItemTableViewCell: UITableViewCell, ReactiveView {
1616
@IBOutlet var recentSearchLabel: UILabel!
1717

1818
func bindViewModel(viewModel: AnyObject) {
19-
let previousSearch = viewModel as PreviousSearchViewModel
19+
let previousSearch = viewModel as! PreviousSearchViewModel
2020
recentSearchLabel.text = previousSearch.searchString
2121
totalResultsLabel.text = "\(previousSearch.totalResults)"
2222

ReactiveSwiftFlickrSearch/View/SearchResultsTableViewCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SearchResultsTableViewCell: UITableViewCell, ReactiveView {
1818
@IBOutlet var titleLabel: UILabel!
1919

2020
func bindViewModel(viewModel: AnyObject) {
21-
let photo = viewModel as SearchResultsItemViewModel
21+
let photo = viewModel as! SearchResultsItemViewModel
2222
titleLabel.text = photo.title
2323

2424
self.clipsToBounds = true

ReactiveSwiftFlickrSearch/View/SearchResultsViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class SearchResultsViewController: UIViewController, UITableViewDelegate {
3838

3939
func scrollViewDidScroll(scrollView: UIScrollView!) {
4040
let cells = searchResultsTable.visibleCells()
41-
for cell in cells as [SearchResultsTableViewCell] {
41+
for cell in cells as! [SearchResultsTableViewCell] {
4242
let value = -40.0 + (cell.frame.origin.y - searchResultsTable.contentOffset.y) / 5.0;
4343
cell.setParallax(value)
4444
}

ReactiveSwiftFlickrSearch/ViewModel/FlickrSearchViewModel.swift

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class FlickrSearchViewModel: NSObject {
1717

1818
dynamic var searchText = ""
1919
dynamic var previousSearches: [PreviousSearchViewModel]
20-
let executeSearch: RACCommand!
20+
var executeSearch: RACCommand?
2121
let title = "Flickr Search"
22-
let previousSearchSelected: RACCommand!
23-
let connectionErrors: RACSignal!
22+
var previousSearchSelected: RACCommand!
23+
var connectionErrors: RACSignal!
2424

2525
private let services: ViewModelServices
2626

@@ -42,14 +42,15 @@ class FlickrSearchViewModel: NSObject {
4242
(any:AnyObject!) -> RACSignal in
4343
return self.executeSearchSignal()
4444
}
45-
connectionErrors = executeSearch.errors
45+
connectionErrors = executeSearch!.errors
4646

4747
previousSearchSelected = RACCommand() {
4848
(any:AnyObject!) -> RACSignal in
49-
let previousSearch = any as PreviousSearchViewModel
49+
let previousSearch = any as! PreviousSearchViewModel
5050
self.searchText = previousSearch.searchString
5151
return self.executeSearchSignal()
5252
}
53+
5354
}
5455

5556
//MARK: Private methods

0 commit comments

Comments
 (0)