views:

46

answers:

3

In my code I declared NSString object in .h and synthesized in .m , I m assigning it with string object in array . but its not working .

when I print it on Log it display sometime CAlayer Class , some time shows NSCFString class object .some time shows UIDevicewhitedevicetype class how to solve this ? help...

A: 

How are you assigning the string to the NSString object in your code?

Are you doing something like:

NSString* someString = @"My string";
self.myStringProperty = someString;

Where myStringProperty is the NSString declared as a property.

James Raybould
A: 

I think your memory is ruined. You maybe release something that should not be released.

Toro
A: 

The reference is definitely bad. You said you are assigning the string to a property. Does that imply that in your header you have something like:

@property (assign) NSString* myString;

If so, that explicitly states that you are not going to hold onto the string reference, allowing it to be dealloced even if you still hold a pointer (not a reference) to it. You should make it say either:

@property (copy) NSString* myString;
@property (retain) NSString* myString;

If you are pointing your string at a value in an array, as soon as that array is released all of its contents are released. If you aren't holding a retained reference to the string it will be deallocated. Once that has happened the pointer you have stored points to undefined memory that is being reused to hold the object types you listed.

Peter