Attempt to use unknown class for method calls floatValue of NSNumber

I have two NSNumber objects declared as properities in the header file. I am trying to access it and get float value out of it. I get the following error and the code crashes on the first line...

Attempt to use unknown class


Here is the code...

    float avgCals=0, avgSteps=0;
    avgCals = [chartOperator.weeklyAvgCal floatValue];
    avgSteps = [chartOperator.weeklyAvgSteps floatValue];
    [weeklyAvgStepsLabel setText:[NSString stringWithFormat:@"Avg. Steps: %0.02f",avgSteps]];
    [weeklyAvgCalLabel setText:[NSString stringWithFormat:@"Avg. Cals: %0.02f",avgCals]];


it crashes at line 2


what could be the problem?

Hovering mouse pointer over 'chartOperator' shows the object is not nil and so aren't weeklyAvgCal and weeklyAvgSteps.

Where does it crash ?

Line 01 or line 02 ?


How is chartOperator defined ?

Shouldn't you be accessing the property via "self."? There must be something else going on in the code you haven't shown.

Line 02 I chose a workaround. Instead of capturing the average in NSNumber i wrote scalar properties in the ChartOperator class and accessed those to get the average.

Not self. They are in another class called ChartOperator the pointer to which is chartOperator.

Upon checking the debugger output i learnt that it was passing the floatValue getter call to some CALayer which was incorrect. Must be an xcode bug. I was making those calls on an NSNumber property in ChartOperator. Bad linking maybe.

So, ChartOperator is a class of yours ?

You did not tell where exactly the crash was.


Could you show how it is declared and how properties are set ?

If you debug your code and break on one of those lines you will be able to see what class those pointers really are. I'm sure it is not an Xcode bug.

weeklyAvgSteps and weeklyAvgCals were NSNumber

So, ChartOperator is a class of yours ?

Yes.


You did not tell where exactly the crash was.

line 02 in the above code


Could you show how it is declared and how properties are set ?

@property (nonatomic, assign) NSNumber *avgWeeklyCal, *avgWeeklySteps;

"Attempt to use unknown class" may happen when your heap is broken.


Which may be caused by

- Wrong pointer manipulation

- Touching thread-unsafe things from mutiple threads

- ...


Anyway, you may need to examine all other parts of your code.


Can you create a minimized project which can reproduce the same issue?

The problem could be in ChartOperator.


Could you post the complete code of the class ?


Could this be similar problem as here, where argument type was lost on call, because of some copying ?

https://stackoverflow.com/questions/60438591/sigabrt-attempt-to-use-unknown-class-projectnameexc-bad-access-error-on-a-stro

Attempt to use unknown class for method calls floatValue of NSNumber
 
 
Q