mhacks / mhacks-ios

The official MHacks iOS app
https://mhacks.org
22 stars 6 forks source link

Hack using `locationForID` and initialization of APIManager #4

Closed manavgabhawala closed 8 years ago

manavgabhawala commented 8 years ago

There currently exists this really weird hack in the APIManager to allow initialization to happen without a race condition and to sort out dependencies. The problem is APIManager.sharedManager() initializes a new instance the first time it is called and tries to unarchive itself from disk if the disk store exists. However, the initializer of Event needs to have access to the Location store in order to be initialized. The problem is the store is in the APIManager instance we are creating so there is this weird cycle of initializing the manager means initializing events but to initialize events we need access to the manager's location store. So to fix-it, rather hack-ily, we register a callback and the Event initializer uses the callback instead. Note, it isn't feasible to pass the callback in as an argument to the constructor so of course its a global callback. A fix for this would be really useful in cleaning up this hack.