开发者

NSString not working

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...


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜