From bda14c48c78713e5d4177653a00ee96dfd07a3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20B=C3=B8geskov?= Date: Mon, 18 Jan 2016 19:41:28 +0100 Subject: [PATCH] Added reactive wrapper for the network activity indicator in UIApplication. --- RxCocoa/iOS/UIApplication+Rx.swift | 37 +++++++++++++++++++ RxExample/RxExample.xcodeproj/project.pbxproj | 4 ++ 2 files changed, 41 insertions(+) create mode 100644 RxCocoa/iOS/UIApplication+Rx.swift diff --git a/RxCocoa/iOS/UIApplication+Rx.swift b/RxCocoa/iOS/UIApplication+Rx.swift new file mode 100644 index 00000000..a4072294 --- /dev/null +++ b/RxCocoa/iOS/UIApplication+Rx.swift @@ -0,0 +1,37 @@ +// +// UIApplication+Rx.swift +// RxExample +// +// Created by Mads Bøgeskov on 18/01/16. +// Copyright © 2016 Krunoslav Zaher. All rights reserved. +// + +import Foundation + +#if os(iOS) || os(tvOS) + import UIKit + +#if !RX_NO_MODULE + import RxSwift +#endif + + extension UIApplication { + + /** + Bindable sink for `networkActivityIndicatorVisible`. + */ + public var rx_networkActivityIndicatorVisible: AnyObserver { + return AnyObserver { event in + MainScheduler.ensureExecutingOnScheduler() + switch event { + case .Next(let value): + self.networkActivityIndicatorVisible = value + case .Error(let error): + bindingErrorToInterface(error) + case .Completed: + break + } + } + } + } +#endif \ No newline at end of file diff --git a/RxExample/RxExample.xcodeproj/project.pbxproj b/RxExample/RxExample.xcodeproj/project.pbxproj index 2ad924d9..5678ef49 100644 --- a/RxExample/RxExample.xcodeproj/project.pbxproj +++ b/RxExample/RxExample.xcodeproj/project.pbxproj @@ -422,6 +422,7 @@ CBEE77541BD8C7B700AD584C /* ToArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBEE77531BD8C7B700AD584C /* ToArray.swift */; }; D2245A191BD5654C00E7146F /* WithLatestFrom.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2245A0B1BD564A700E7146F /* WithLatestFrom.swift */; }; D2AF91981BD3D95900A008C1 /* Using.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2AF91881BD2C51900A008C1 /* Using.swift */; }; + E3EE18D21C4D68F900834224 /* UIApplication+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3EE18D11C4D68F900834224 /* UIApplication+Rx.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -927,6 +928,7 @@ CBEE77531BD8C7B700AD584C /* ToArray.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToArray.swift; sourceTree = ""; }; D2245A0B1BD564A700E7146F /* WithLatestFrom.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WithLatestFrom.swift; sourceTree = ""; }; D2AF91881BD2C51900A008C1 /* Using.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Using.swift; sourceTree = ""; }; + E3EE18D11C4D68F900834224 /* UIApplication+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+Rx.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1596,6 +1598,7 @@ C89465591BC6C2BC0055219D /* UITextView+Rx.swift */, 842A5A251C357F21003568D5 /* NSTextStorage+Rx.swift */, 9B4612941C106CF100BBBB4E /* UIActivityIndicatorView+Rx.swift */, + E3EE18D11C4D68F900834224 /* UIApplication+Rx.swift */, 8479BC6D1C3BC99C00FB8B54 /* UIImagePickerController+Rx.swift */, ); path = iOS; @@ -2403,6 +2406,7 @@ C8984C491C36A579001E4272 /* SectionModel.swift in Sources */, C83367251AD029AE00C668A7 /* ImageService.swift in Sources */, C86E2F471AE5A0CA00C31024 /* WikipediaSearchResult.swift in Sources */, + E3EE18D21C4D68F900834224 /* UIApplication+Rx.swift in Sources */, C8984CD11C36BC3E001E4272 /* NumberCell.swift in Sources */, C8A2A2C81B4049E300F11F09 /* PseudoRandomGenerator.swift in Sources */, C8D132151C42B54B00B59FFF /* UIImagePickerController+RxCreate.swift in Sources */,