使用弧,初始化后,我的ivars为空

最新的testing:我放了一个NSLog(@"%p", self.myArray); 数组赋值后,我看到一个地址实际logging…..!?!?!

 2012-03-06 01:33:52.618 ArrayTest[9883:f803] 0xae0f160 

看来,如果Xcode无法在局部variables或工具提示突出显示方法中看到该ivar的地址,那么它就被全部解决了。

思考?

最新testing:我创build了一个全新的项目。

看起来简单的将对象分配给ivars根本不起作用。 如果在分配新创build的数组之后查看myArray的地址,则它具有空地址。

输出nslog

 2012-03-06 01:30:37.283 ArrayTest[9848:f803] ( ) (lldb) // // ViewController.h // ArrayTest // // Created by Ben J Brown on 3/6/12. // Copyright (c) 2012StudioBflat. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController { NSMutableArray *myArray; } @property (strong) NSMutableArray *myArray; @end // // ViewController.m // ArrayTest // // Created by Ben J Brown on 3/6/12. // Copyright (c) 2012 StudioBflat. All rights reserved. // #import "ViewController.h" @implementation ViewController @synthesize myArray; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSMutableArray *array = [NSMutableArray arrayWithCapacity:16]; self.myArray = array; 

的NSLog(@ “%@”,self.myArray); }

 - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } else { return YES; } } @end 

更老的数据:

在我的viewDidLoad中我有:

 NSLog(@"%@",self.collectionOfImageViews); self.collectionOfImageViews = [[NSMutableArray alloc] initWithCapacity:NUMBER_OF_COLUMNS*NUMBER_OF_ROWS]; NSLog(@"%@",self.collectionOfImageViews); 

然而,当我访问该数组时,数组有一个地址,但是我添加到它的所有对象都消失了,当我向该对象发送一个计数消息(NSMutableArray)时,它会在控制台中引发这个事件:

 -[UIImage count]: unrecognized selector sent to instance 0x6b7ab40 

我的界面中的属性:

 @property(strong) NSMutableArray* collectionOfImageViews; 

我有@synthesize collectionOfImageViews; 在我的@implmentation之后…我在这里错过了什么?

这里是我收集的地方:

  NSLog(@"%@",self.collectionOfImageViews); self.collectionOfImageViews = [[NSMutableArray alloc] initWithCapacity:NUMBER_OF_COLUMNS*NUMBER_OF_ROWS]; NSLog(@"%@",self.collectionOfImageViews); 

在这个动作之后,看着它有一个空地址的数组….

关于那个早先的奇怪的错误,我安慰它是一个UIImage没有响应计数…我通过改变界面中的伊娃尔声明的顺序来修正:

 #import <UIKit/UIKit.h> #import "TiledImageView.h" @interface ViewController : UIViewController <TiledImageViewDelegation> { NSMutableArray *collectionOfImageViews; UIImage *sourceImage; UIImageView *currentTappedView; } @property(strong) NSMutableArray* collectionOfImageViews; @property(strong) UIImage* sourceImage; @property(strong) UIImageView* currentTappedView; @end 

至于我在哪里填充可变数组,那么这里是代码:

 iView = [[TiledImageView alloc] initWithImage:[UIImage imageWithCGImage:tempImage]]; iView.userInteractionEnabled = YES; iView.delegate = self; iView.contentMode = UIViewContentModeScaleAspectFit; [iView setTag:index]; [iView setPosX:column]; [iView setPosY:row]; [collectionOfImageViews addObject:iView]; 

我很困惑,因为这是简单的伊娃设置和获取..和分配和初始化…我已经做了很多次之前,但似乎我的ivars不活着…我是新来的ARC。

这似乎是一个LLDB错误。 改为使用GDB进行debugging。

编辑:这显然是lldb中的一个bug,我已经在3月份提交了一个bug报告(它被标记为另一个bug,后来被标记为closures)的重复 – 这个问题已经在更新的Xcode版本中得到解决。

你得到()的事实意味着数组没有错。 您可以通过添加任何其他对象(如NSNumber),然后再次logging该数组来轻松地进行testing,您应该在那里看到您的对象。 关于内存地址,如果你正在使用debugging器,你应该在分配数组的指令之后设置断点,然后你就可以看到数组的内容。 否则,如果你的断点不在那里,谁知道你会看到什么。

最后, – [UIImage计数]:无法识别的select器发送到实例0x6b7ab40意味着你正在试图使一个UIImage对象执行一个计数方法,这是不存在的,你可能要数组而不是内部的对象。 所以问题出在你调用这个方法的地方,在引用对象或者ivar时,你似乎很难,为了避免这种情况,在综合中改变@synthesize collectionOfImageViews; 到@synthesize collectionOfImageViews = collectionOfImageViews;

也可以尝试像其他人一样改变编译器。