James Dunay
James Dunay

Reputation: 2724

Pulling an NSArray out of a NSMutableArray

I have an NSMutableArray which is storing a list of other arrays. And when i run the code.

NSLog(@"%@",[[appDelegate teamRoster]objectAtIndex:[indexPath.row]class])

It returns and tells me that i am looking at an Array,

however when i try to do the following

[selectedRowerView tempArray] = [[appDelegate teamRoster]objectAtIndex:[indexPath.row]];

The program errors out. Anyone have any ideas why this might be happening?

Upvotes: 1

Views: 93

Answers (2)

Regexident
Regexident

Reputation: 29552

How about this?

selectedRowerView.tempArray = [[appDelegate teamRoster]objectAtIndex:[indexPath.row]];

…assuming that tempArray is a synthesized property à la

@property (nonatomic, readwrite, retain) NSArray *tempArray;

@synthesize tempArray;

Clarification:

selectedRowerView.tempArray = …;

gets internally processed to

[selectedRowerView setTempArray:…];

which is a setter method.

While

selectedRowerView.tempArray;

gets internally processed to

[selectedRowerView tempArray];

which is a getter method.

Subtle but important difference.
The meaning of foo.bar depends on the very context (enclosing expression) it is used in.

Upvotes: 1

AWF4vk
AWF4vk

Reputation: 5890

You have to understand that [selectedRowerView tempArray] is actually a command / message that is being sent. In C++ equivalent, you are calling selectedRowerView->tempArray() = .... Which doesn't make logical sense because you cannot make an assignment to a function.

What you're trying to do is set the tempArray. If you have the proper setters/getters set-up, you can just run: selectedRowerView.tempArray = ...;

Just make sure that tempArray has a @property and is @synthesize'd.

Upvotes: 3

Related Questions