我有一个变量值奇怪的问题。这是该代码(这是一个类方法的一部分):iphone nslog损坏的数据
MyAppDelegate *pDelegate = [[UIApplication sharedApplication] delegate];
SomeDictionaryData *appData = [pDelegate.theData retain];
NSLog(@"my instance var: %@",cardIndex); // outputs "my instance var: 4"
NSDictionary *currentCard = [[NSDictionary alloc] initWithDictionary:[appData.cards objectAtIndex:cardIndex]];;
// the above line breaks the app
[currentCard release];
[appData release];
我使用与objc_exception_throw
断点调试器。 objectAtIndex
在那里收到的输入显示为值= 13760640. appData的cards
属性是NSArray
,它显然没有1000万以上的项目,所以我得到了一个超出界限的错误。我试着用(int)cardIndex
铸造没有更好的结果。奇怪的是一些其他类中的类似代码很好。
这是我想要在整个应用程序中使用的一些数据,所以我有一个Model类,它在AppDelegate中被初始化为theData
,然后被不同的ViewController加以使用。在其他一些ViewController上成功访问后,会出现此错误(该错误也会保留/释放)。
任何帮助将不胜感激。
谢谢兄弟!虽然我得到一个“无效的接收器类型int”警告。 – mga 2009-08-25 02:44:27
尝试投射为(NSUInteger)并仍然收到警告。其他一切正常,但...我只是不喜欢警告。 – mga 2009-08-25 02:45:30
对!将所有必要的引用转换为NSNumber。谢谢! – mga 2009-08-25 03:45:14