Noob here trying to use dependency injection and not entirely understanding all the parts.
I have a custom CLLocationManagerDelegate class that gets user location by lat/long if locationservices are authorized, and then shares it with multiple View Controllers. I’m now trying to save the lat/long to Core Data and I have created another custom PersistanceManager class to handle savingContext and fetching.
Now I’m trying to init the PersistanceManager class in my custom CLLocationManagerDelegate class, but running into some issues with init() that I dont understand.
Here’s I add final class PersistanceManager
right now:
class CustomLocationManager: NSObject {
static let shared = CustomLocationManager()
let persistenceManager: PersistanceManager
private var locationManager = CLLocationManager()
weak var delegate: LocationServicesDelegate?
private override init() {
self.persistenceManager = persistenceManager * ERROR
super.init()
setupLocationServices()
}
convenience init(persistenceManager: PersistanceManager) {
self.init(persistenceManager: persistenceManager)
}}
I get an error "Assigning property to itself " at the error.
I understand that convenience init is secondary and so I thought I should init the PersistanceManager first so it exists before the CustomLocationManager’s super.init() is called. So why am I getting this error?