0

Well, in obj-c have the ability of change the class of a declared var. So if I declare myVar as a NSString, is possible to get back later a NSNUmber.

I have this problem now, but I can't find where in my code is the identity swap... exist a way to find it? For example is possible to set a breakpoint where [myVar class] == [NSString class] and when change know it?

mamcx
  • 15,916
  • 26
  • 101
  • 189
  • This might be helpful: http://stackoverflow.com/questions/1040585/watching-variables-in-xcode or this http://stackoverflow.com/questions/4801175/tracking-variable-or-memory-change-in-xcode – SteAp Sep 23 '11 at 22:06

1 Answers1

3

You may be confused about the static type of a pointer, and the actual type of the object it points to. Consider this code:

NSString *test = @"test";
NSNumber *notReallyANumber = (NSNumber *)test;

This is valid code, but it didn't "transform" test into an NSNumber. It's still a string, just with an incorrect type on the pointer.

Basically, no, you don't have the ability to change the class of a variable (you do, but it's deep deep magic and almost never occurs).

Catfish_Man
  • 41,261
  • 11
  • 67
  • 84
  • I think he has another problem: An assignment which shouldn't happen. An @macmcx tries to locate the statement, which performs the assignment. – SteAp Sep 23 '11 at 22:09
  • Yes that is the thing. And the typecast could be the issue, the problem is detect when... I could review all the code but hope exist a less time consuming option.. – mamcx Sep 23 '11 at 22:57