开发者

Obj-c let me change the class of a variable, and its bad: How hunt it?

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 h开发者_运维技巧ave 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?


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜