Created
November 27, 2016 21:25
-
-
Save nazmulkp/7eff3dc3b9000066a9ed70d9c3dd9e8e to your computer and use it in GitHub Desktop.
Building the Signals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fetchJSON(from url: URL) -> RACSignal { | |
print("Fetching: \(url.absoluteString)") | |
// 1 | |
return RACSignal.createSignal({(_ subscriber: RACSubscriber) -> RACDisposable in | |
// 2 | |
var dataTask = self.session.dataTask(withURL: url, completionHandler: {(_ data: Data, _ response: URLResponse, _ .error: Error) -> Void in | |
// TODO: Handle retrieved data | |
}) | |
// 3 | |
dataTask.resume() | |
// 4 | |
return RACDisposable(block: {() -> Void in | |
dataTask.cancel() | |
}) | |
}).doError({(_ error: Error) -> Void in | |
// 5 | |
print("\(.error)") | |
}) | |
} |
class func sharedManager() -> Self {
var sharedManager: Any? = nil
var onceToken: dispatch_once_t
dispatch_once(onceToken, {() -> Void in
self.sharedManager = self.init()
})
return sharedManager
}
override init() {
super.init()
// 1
self.locationManager = CLLocationManager()
self.locationManager.delegate = self
// 2
self.client = WXClient()
// 3
RACObserve(self, currentLocation).ignore(nil).flattenMap({(_ newLocation: CLLocation) -> Void in
return RACSignal.merge([self.updateCurrentConditions(), self.updateDailyForecast(), self.updateHourlyForecast()])
// 6
}).deliver(on: RACScheduler.mainThreadScheduler).subscribeError({(_ error: Error) -> Void in
TSMessage.showNotification(withTitle: "Error", subtitle: "There was a problem fetching the latest weather.", type: TSMessageNotificationTypeError)
})
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.