Search code examples
objective-cxcodeconstantsexc-bad-access

Unable to read NSString * const in Objective C


In my header file, I declared

extern NSString * const UserDefault_ClusterItemWidth;

And in my implement file I gave it a value

NSString * const UserDefault_ClusterItemWidth = @"ClusterItemWidth";

Everything seems right, but when I called it

[[NSUserDefaults standardUserDefaults] setFloat:0.0f forKey:UserDefault_ClusterItemWidth];

I got

Thread 1: EXC_BAD_ACCESS (code=2, address=0x16fb1b700)

and XCode show something like this when I place the mouse on top of the constant

(NSString *const) UserDefault_ClusterItemWidth = 0x0000000100c1c698

Instead of @"ClusterItemWidth"

I am running out of idea on what is happening.

Thanks.


Solution

  • So apparently, I have accidentally created an infinite loop, setting the NSUserDefaults over and over again and causes the app to crush.