Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Why there is no Subscription to onContactsDataProviderErrorSignal event in OHContactDataSource #54

Open
ajaybeniwal opened this issue Apr 1, 2018 · 1 comment

Comments

@ajaybeniwal
Copy link

In all examples we are firing onContactsDataProviderErrorSignal on dataproviders, but there is no subscription to this event in the OHContactDataSource file , so currently it is very difficult to catch NSError from api calls in view controllers. So want to ask how to catch NSError events in viewcontroller using onContactsDataProviderErrorSignal , documentation lacks how to handle errors gracefully if we are loading contacts from remote datasource

@NickEntin
Copy link
Contributor

Hi Ajay, the data source itself doesn't handle errors from the data providers. Instead, you should add your view controller as the observer for the onContactsDataProviderErrorSignal on each of the data providers you are using. So, in your view controller class, you will have something along the lines of:

// Initialize the data provider.
let dataProvider = OHCNContactsDataProvider(delegate: self)

// Add the error handler.
dataProvider.onContactsDataProviderErrorSignal.addObserver(self, callback: { (error, dataProvider) in
    // Handle the error.
})

// Initialize the data source.
let dataSource = OHContactsDataSource(dataProviders: NSOrderedSet(objects: dataProvider), postProcessors: NSOrderedSet())

dataSource.onContactsDataProviderFinishedLoadingSignal.addObserver(self, callback: { (contacts) in
    // Everything was successful.
})

// Load the contacts from the data provider into the data source.
dataSource.loadContacts()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants