Re: Some advice requested on debugging a difficult problem. iOS.

Jack Brindle


I think you may be going down the wrong path on this one. It sounds more like a second instance is being created somehow. Did you guard the init method so that no one can create a second one, or are you sure that the dictionary is not being released before you actually use it?

As for guarding the init - in a singleton I always have the singleton accessor call a method named something like initOnce that is not accessible outside the class file, the code an init method that returns nil. Anyone calling init on the class will get the nil response.

Hope this helps.


On Mar 26, 2019, at 8:53 AM, Alex Zavatone via Groups.Io <zav@...> wrote:

In the iOS app that I’m working on now, we have a problem that I’ve never seen in my years as an iOS programmer.

While we have a 99.7% crash free user experience, what does crash is weird as fuck.

By that, I mean that data that normally exists in a dictionary most of the time suddenly becomes nil.

It was today when I noticed this.

@property(strong, nonatomic, readwrite,getter=getRootAPIData) NSDictionary *rootUrlMap;

See how we have an accessor defined for rootUrlMap to be getRootAPIData? (Yes, that get is bad form, i know.)

Well, we never use it.

We always access it like so, [AppEnvironment sharedEnvironment].appContext.rootUrlMap;

And there is only one instance of getRootAPIData in the app… where it is defined.

And here’s my question. Would directly accessing the property via the property name, even when its getter is defined to be something else, would this occasionally result in a nil return?

So, what happens when you define a getter of an object’s property to be something else, yet still try to get a value from the name of the property?

We have a lot of sloppy programming, including a lot of the hacky safeObjectForKey: to prevent crashing when accessing a value from a dictionary when you assume that the dictionary is not nil and I’m trying to sort out all this slop.

Thanks in advance,
Alex Zavatone

Join { to automatically receive all group messages.