PDA

View Full Version : Variable is not a CFString at this time - Error




Young Developer
Aug 26, 2012, 01:52 PM
I have got this error during the debugging through device. In simulator it is working fine. How to solve that issue?

- (IBAction)buttonDigitPressed1: (UIButton *)button
{
NSString *integerPart = [SDKRegistry returnNSStringFromComponent:@"integerPart"];

NSLog(@"class is %@",[integerPart class]);
NSLog(@"pointer is %p", integerPart);

if (!integerPart) integerPart = @"";
NSString *one = @"1";
integerPart = [SDKRegistry updateRegistryComponent:@"integerPart" withString:
[integerPart stringByAppendingString: one]];
[self performConversion];
}

class is __NSCFConstantString pointer is 0x5922c

When I am pressing number "1", appears that error - integerPart - "Variable is not a CFString at this time"

I have tried to made the following in .m file:

NSString *integerPart; @property (nonatomic, retain) NSString *integerPart;

then in .h file:

@synthesize integerPart;

and change the code above:

integerPart = [[NSString alloc] initWithString:[SDKRegistry returnNSStringFromComponent:@"integerPart"]];
...
[integerPart release];

But nothing was changed. Please help me to find an answer to solve this.



dejo
Aug 27, 2012, 09:55 AM
What is SDKRegistry?

Young Developer
Aug 27, 2012, 12:42 PM
@interface SDKRegistry : NSObject
{
}
+ (NSString *)returnNSStringFromComponent: (NSString *)component;


@implementation SDKRegistry : NSObject

+ (NSString *)returnNSStringFromComponent: (NSString *)component
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
return [defaults stringForKey:component];
}

idelovski
Aug 27, 2012, 01:56 PM
Looks like you over-released or failed to retain that variable and then something else pops in that block of memory. Simulator has much more free memory and that's why that block is not reused immediately.

Other than that, the last line in the method - buttonDigitPressed1: makes no sense; you have formed this integerPart string and then what? Why do you need it in the first place? I think there is more than what we have here.

;)

Could it be the last line [self performConversion] is actually [self performSelector... afterDelay:...];

dejo
Aug 27, 2012, 02:51 PM
A few more concerns:

- You haven't shown how updateRegistryComponent:withString: is defined.

- As idelovski mentioned, why reassign integerPart and then do nothing with it?

- You haven't shown what performConversion is.

- Which line is giving you the "Variable is not a CFString at this time" error?

Young Developer
Aug 27, 2012, 03:39 PM
+ (NSString *)updateRegistryComponent: (NSString *)component withString: (NSString *)value
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults setValue:value forKey:component];
[defaults synchronize];

return value;
}


performConversion - only update the screen.

But error appears before it on the line:
if (!integerPart) integerPart = @""; // "Variable is not a CFString at this time"

dejo
Aug 27, 2012, 03:42 PM
Please see this sticky before you provide anymore code: Posting code, please use the [CODE] tags (http://forums.macrumors.com/showthread.php?t=747660)

EDIT:

What do your NSLogs show?

Young Developer
Aug 27, 2012, 04:35 PM
class is __NSCFConstantString

pointer is 0x5922c