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


Alex Zavatone
 

I just replicated this in a sample and ran a short test to see what the results are.  

@interface MyObject : NSObject

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

@end



@implementation MyObject

- (id)init {
    if (self == [super init]) {
        _rootUrlMap = [NSDictionary dictionaryWithObjectsAndKeys:@"Hi",@"myKey", nil];
    }
    return self;
}

@end



    MyObject *myObject = [MyObject new];

    

    NSLog(@"%@", myObject.rootUrlMap);
    NSLog(@"%@", myObject.getRootAPIData);
    NSLog(@"%@", [myObject getRootAPIData]);


2019-03-26 11:01:30.116353-0500 Test[80252:7074112] {
    myKey = Hi;
}
2019-03-26 11:01:30.116528-0500 Test[80252:7074112] {
    myKey = Hi;
}
2019-03-26 11:01:30.116654-0500 Test[80252:7074112] {
    myKey = Hi;
}

So, the getter and the property name both allow accessing the property.

But should we expect it to if the getter has been redefined?

Thanks again.
Alex Zavatone


On Mar 26, 2019, at 10: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 {cocoa@apple-dev.groups.io to automatically receive all group messages.