0

MOST NEW TESTING: I placed a NSLog(@"%p", self.myArray); after the array assignment and I am seeing a address actually logged.....!?!?!

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

Seems that Xcode is all wacked out if it cant see the addess of that ivar in either local variables or with the tool tip highlight method...

Thoughts?

NEWEST TESTING: I created a brand new project.

It seems that simple assigning of objects to ivars is not working at all. If I look at the address of myArray after the assignment of the newly created array it has a null address.

output of 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

OLDER DATA:

In my viewDidLoad I have:

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

However later on when I access that array the array has an address but all the objects that I added to it are gone, and when I send a count message to that object(the NSMutableArray) it throws this in the console:

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

My properties in my interface:

@property(strong) NSMutableArray* collectionOfImageViews;

and I have @synthesize collectionOfImageViews; right after my @implmentation... what am I missing here?

Here is where I make the collection:

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

looking at the array it has a null address right after this action....

Concerning that earlier weird error where I had it consoling out that it was a UIImage not responding to count... I fixed that kinda by changing the order of the ivar declarations in the interface:

#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

As for where I fill the mutable array later here is that code:

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];

I'm pretty darnd confused because this is simple ivar setting and getting.. and alloc and initialization... something I have done many times before but it seems my ivars are not staying alive... I'm new to ARC.

Lesmana
  • 25,663
  • 9
  • 82
  • 87
theprojectabot
  • 1,163
  • 12
  • 19
  • Are you sure you are looking at the same object? Is `self` the same at both times? You might have one object that you created, and one that got loaded from a nib, or something similar. (Also, they aren't "class properties", they are "instance variables" or "ivars".) – Kurt Revis Mar 06 '12 at 07:43
  • if you NSLog("%@",self.collectionOfImageViews); do you get ( ) or (null)? – Pochi Mar 06 '12 at 07:45
  • Your error message suggests that at the time the error is thrown, `collectionOfImagesViews` points at an object of type UIImage instead of an array. Perhaps there's a problem in your code where you are adding your image objects? – jonkroll Mar 06 '12 at 07:47
  • please show us the code where you add the objects to your array – Martin Ullrich Mar 06 '12 at 07:49
  • fixed that sorry. that was just a question typo... – theprojectabot Mar 06 '12 at 08:20
  • 1
    Please post the code where you are accessing this array. and paste exactly what is the console output to NSLog(@"%@",self.collectionOfImageViews); after the init. thx – Pochi Mar 06 '12 at 08:28
  • Did you check that iView is a valid instance before adding it to the array? could you try to NSLog it? – superandrew Mar 06 '12 at 08:37
  • i did and it is valid... the crazy thing is that the variables view in xcode is showing that after my nsmutuablearray has been alloc'd and init'd it is still null... address is a bunch of zeros... and I have cleaned the project in a last ditch effort to make it work... – theprojectabot Mar 06 '12 at 08:42
  • (lldb) po collectionOfImageViews (NSMutableArray *) $10 = 0x00000000 – theprojectabot Mar 06 '12 at 08:44
  • @LuisOscar I get () after the alloc for the NSLog() but xcode still shows the address of the array as null... – theprojectabot Mar 06 '12 at 09:12
  • You showed us some `NSLog` statements, but didn't show us the output. You told use you got an unrecognized selector exception, but you didn't show us the stack trace, or any code that even sends the `count` message. Please add this information to your question. You need to [set an exception breakpoint](http://stackoverflow.com/questions/4961770/run-stop-on-objective-c-exception-in-xcode-4) to get the stack trace of the exception. – rob mayoff Mar 06 '12 at 09:14
  • @robmayoff I have run a new project and the simple assignment problem is the root of the problem. I dont konw why its happening. – theprojectabot Mar 06 '12 at 09:32
  • @LuisOscar I have reposted new code showing a very simple test that displays the ivar assigment problem I am encountering. – theprojectabot Mar 06 '12 at 09:33
  • try deleting the ivar completely from your .h file.. @synthesize creates the ivar for you so no need for redefinition. you should use "@synthesize myProp=_myProp;" so your ivar will be called _myProp to distinguish between ivars and accessor properties – Martin Ullrich Mar 06 '12 at 09:36
  • and anyway.. are your compilation-settings correct?. – Martin Ullrich Mar 06 '12 at 09:37
  • @MartinUllrich I tried what you requested and I am still having Xcode show nothing. The %p nslog does show the address but xcode does not. As reported at the top of this long question. Thanks for all your help btw! – theprojectabot Mar 06 '12 at 09:40
  • if you upload your new project, we could have a look at it.. it would be interesting because this is a really strange issue – Martin Ullrich Mar 06 '12 at 09:46
  • @MartinUllrich here is a link : https://www.dropbox.com/sh/0y9s0su7wx6nhan/wicXAG0f5Z/ArrayTest.zip – theprojectabot Mar 06 '12 at 09:49
  • I tried the sample project. this is what I got in the debugger: http://i.imgur.com/tMkKQ.png Can anyone explain why `self.myArray` and `self->myArray` are different? – Felix Mar 06 '12 at 10:11
  • seems to be an issue with LLDB, when I use GDB debugger everything looks ok http://i.imgur.com/GeoQU.png – Felix Mar 06 '12 at 11:00
  • Yes.. if you add NSLog(@"%p", _myArray); it works fine. your problem with [UIImage count] seems to be a different one.. – Martin Ullrich Mar 06 '12 at 11:04
  • 1
    http://stackoverflow.com/questions/9482689/uiviewcontroller-subclass-cant-assign-instance-variable – theprojectabot Mar 06 '12 at 17:46
  • seems LLDB for ios is sucky right now, use gdb. http://stackoverflow.com/questions/9482689/uiviewcontroller-subclass-cant-assign-instance-variable – theprojectabot Mar 06 '12 at 17:47
  • Cant fit my description here, i have posted it in the answer section. – Pochi Mar 07 '12 at 00:12

2 Answers2

1

This seems to be an LLDB bug. Use GDB for debugging instead.

edit: It obviously is a bug within lldb, i have filed a bug report back in march (it was marked as a duplicate of another bug which was later marked as closed) - the issue has been resolved in newer Xcode versions.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • I had same issue, switch to using GDB and it now correctly shows my ivars as not being nil. Considering the latest version of XCODE insists you switch to using LLDB this is a big bug! – Camsoft Mar 16 '12 at 11:43
0

The fact that u get () means that there is nothing wrong with the array. You can test it easily by adding any other object like an NSNumber and then logging the array again, you should see your object there. About the memory address, If you are using the debugger you should set the break point AFTER the instruction where the array is allocated, then you will be able to see the contents of the array. Otherwise if your break point is not there who knows what you will be seeing.

Finally the -[UIImage count]: unrecognized selector sent to instance 0x6b7ab40 Means you are trying to make an UIImage object perform a count method, which doesn't exist, You probably want the count on the array not the object inside. So the problem is in where you are calling this method, you seem to have a hard time when it comes to referencing either the object or the ivar, to avoid this, on the synthesize change the @synthesize collectionOfImageViews; to @synthesize collectionOfImageViews = collectionOfImageViews;

Also try changing the compiler like others have suggested.

Pochi
  • 13,391
  • 3
  • 64
  • 104